45 {
46 SocketContextUpgrade* socketContext = nullptr;
47
48 if (
request->
get(
"Sec-WebSocket-Version") ==
"13") {
49 std::string requestedSubProtocolNames =
request->
get(
"sec-websocket-protocol");
50
51 std::list<std::string> subProtocolNamesList;
52 do {
53 std::string subProtocolName;
54 std::tie(subProtocolName, requestedSubProtocolNames) =
httputils::str_split(requestedSubProtocolNames,
',');
56 subProtocolNamesList.push_back(subProtocolName);
57 } while (!requestedSubProtocolNames.empty());
58
59 if (!subProtocolNamesList.empty()) {
60 std::string selectedSubProtocolName;
61
62 socketContext = new SocketContextUpgrade(socketConnection, this);
63 selectedSubProtocolName = socketContext->loadSubProtocol(subProtocolNamesList);
64
65 if (!selectedSubProtocolName.empty()) {
68 response->
set(
"Sec-WebSocket-Protocol", selectedSubProtocolName);
70
72 } else {
73 delete socketContext;
74 socketContext = nullptr;
75
78 }
79 } else {
81
84 }
85 } else {
87
91 }
92
93 return socketContext;
94 }
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)
void checkRefCount() final
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)