2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "web/websocket/server/SocketContextUpgradeFactory.h"
44#include "web/http/server/Request.h"
45#include "web/http/server/Response.h"
46#include "web/websocket/server/SocketContextUpgrade.h"
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
50#include "utils/base64.h"
51#include "web/http/http_utils.h"
70 if (request
->get("Sec-WebSocket-Version") ==
"13") {
71 std::string requestedSubProtocolNames = request
->get("sec-websocket-protocol");
73 std::list<std::string> subProtocolNamesList;
75 std::string subProtocolName;
78 subProtocolNamesList.push_back(subProtocolName);
79 }
while (!requestedSubProtocolNames.empty());
81 if (!subProtocolNamesList.empty()) {
82 std::string selectedSubProtocolName;
87 if (!selectedSubProtocolName.empty()) {
88 response
->set("Upgrade", "websocket");
89 response
->set("Connection", "Upgrade");
90 response
->set("Sec-WebSocket-Protocol", selectedSubProtocolName
);
96 socketContext =
nullptr;
98 response
->set("Connection", "close");
104 response
->set("Connection", "close");
110 response
->set("Sec-WebSocket-Version", "13");
111 response
->set("Connection", "close");
115 return socketContext;
119 static bool linked =
false;
const std::string & get(const std::string &key, int i=0) const
Response & status(int statusCode)
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
static void link(const std::string &upgradeContextName, SocketContextUpgradeFactory *(*linkedPlugin)())
void checkRefCount() final
http::SocketContextUpgrade< web::http::server::Request, web::http::server::Response > * create(core::socket::stream::SocketConnection *socketConnection, web::http::server::Request *request, web::http::server::Response *response) override
std::string name() override
SocketContextUpgradeFactory()=default
SocketContextUpgrade(core::socket::stream::SocketConnection *socketConnection, web::http::SocketContextUpgradeFactory< web::http::server::Request, web::http::server::Response > *socketContextUpgradeFactory)
std::string loadSubProtocol(const std::list< std::string > &subProtocolNames)
std::string serverWebSocketKey(const std::string &clientWebSocketKey)
std::pair< std::string, std::string > str_split(const std::string &base, char c_middle)
std::string & str_trimm(std::string &text)
web::http::server::SocketContextUpgradeFactory * websocketServerSocketContextUpgradeFactory()