MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / accept

Method accept

base/poco/Net/src/WebSocket.cpp:141–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140
141WebSocketImpl* WebSocket::accept(HTTPServerRequest& request, HTTPServerResponse& response)
142{
143 if (request.hasToken("Connection", "upgrade") && icompare(request.get("Upgrade", ""), "websocket") == 0)
144 {
145 std::string version = request.get("Sec-WebSocket-Version", "");
146 if (version.empty()) throw WebSocketException("Missing Sec-WebSocket-Version in handshake request", WS_ERR_HANDSHAKE_NO_VERSION);
147 if (version != WEBSOCKET_VERSION) throw WebSocketException("Unsupported WebSocket version requested", version, WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION);
148 std::string key = request.get("Sec-WebSocket-Key", "");
149 Poco::trimInPlace(key);
150 if (key.empty()) throw WebSocketException("Missing Sec-WebSocket-Key in handshake request", WS_ERR_HANDSHAKE_NO_KEY);
151
152 response.setStatusAndReason(HTTPResponse::HTTP_SWITCHING_PROTOCOLS);
153 response.set("Upgrade", "websocket");
154 response.set("Connection", "Upgrade");
155 response.set("Sec-WebSocket-Accept", computeAccept(key));
156 response.setContentLength(HTTPResponse::UNKNOWN_CONTENT_LENGTH);
157 response.send().flush();
158
159 HTTPServerRequestImpl& requestImpl = static_cast<HTTPServerRequestImpl&>(request);
160 return new WebSocketImpl(static_cast<StreamSocketImpl*>(requestImpl.detachSocket().impl()), requestImpl.session(), false);
161 }
162 else throw WebSocketException("No WebSocket handshake", WS_ERR_NO_HANDSHAKE);
163}
164
165
166WebSocketImpl* WebSocket::connect(HTTPClientSession& cs, HTTPRequest& request, HTTPResponse& response, HTTPCredentials& credentials)

Callers 1

runMethod · 0.45

Calls 11

hasTokenMethod · 0.80
setStatusAndReasonMethod · 0.80
setContentLengthMethod · 0.80
icompareFunction · 0.50
getMethod · 0.45
emptyMethod · 0.45
setMethod · 0.45
flushMethod · 0.45
sendMethod · 0.45
implMethod · 0.45
detachSocketMethod · 0.45

Tested by

no test coverage detected