67 {
68 SocketContextUpgrade* socketContext = nullptr;
69
70 if (
request->
get(
"Sec-WebSocket-Version") ==
"13") {
71 std::string requestedSubProtocolNames =
request->
get(
"sec-websocket-protocol");
72
73 std::list<std::string> subProtocolNamesList;
74 do {
75 std::string subProtocolName;
76 std::tie(subProtocolName, requestedSubProtocolNames) =
httputils::str_split(requestedSubProtocolNames,
',');
78 subProtocolNamesList.push_back(subProtocolName);
79 } while (!requestedSubProtocolNames.empty());
80
81 if (!subProtocolNamesList.empty()) {
82 std::string selectedSubProtocolName;
83
84 socketContext = new SocketContextUpgrade(socketConnection, this);
85 selectedSubProtocolName = socketContext->loadSubProtocol(subProtocolNamesList);
86
87 if (!selectedSubProtocolName.empty()) {
90 response->
set(
"Sec-WebSocket-Protocol", selectedSubProtocolName);
92
94 } else {
95 delete socketContext;
96 socketContext = nullptr;
97
100 }
101 } else {
103
106 }
107 } else {
109
113 }
114
115 return socketContext;
116 }
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)