diff --git a/Framework/Core/src/DPLWebSocket.cxx b/Framework/Core/src/DPLWebSocket.cxx index a39e98c6f5310..d9b6594d5f07c 100644 --- a/Framework/Core/src/DPLWebSocket.cxx +++ b/Framework/Core/src/DPLWebSocket.cxx @@ -276,7 +276,7 @@ void WSDPLHandler::endHeaders() } /// Create an appropriate reply LOG(debug) << "Got upgrade request with nonce " << mHeaders["sec-websocket-key"].c_str(); - std::string reply = encode_websocket_handshake_reply(mHeaders["sec-websocket-key"].c_str()); + std::string reply = encode_websocket_handshake_reply(mHeaders["sec-websocket-key"].c_str(), "dpl"); mHandshaken = true; uv_buf_t bfr = uv_buf_init(strdup(reply.data()), reply.size()); diff --git a/Framework/Core/src/HTTPParser.cxx b/Framework/Core/src/HTTPParser.cxx index 04ca6e8fdce55..fa2ba91722eb0 100644 --- a/Framework/Core/src/HTTPParser.cxx +++ b/Framework/Core/src/HTTPParser.cxx @@ -214,15 +214,16 @@ std::string HTTPParserHelpers::calculateAccept(const char* nonce) return fmt::format("{}", base); } -std::string encode_websocket_handshake_reply(char const* nonce) +std::string encode_websocket_handshake_reply(char const* nonce, const char* protocol) { constexpr auto res = "HTTP/1.1 101 Switching Protocols\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Access-Control-Allow-Origin: \"*\"\r\n" + "{}" "Sec-WebSocket-Accept: {}\r\n\r\n"; - return fmt::format(res, HTTPParserHelpers::calculateAccept(nonce)); + return fmt::format(res, protocol && protocol[0] ? fmt::format("Sec-WebSocket-Protocol: {}\r\n", protocol) : "", HTTPParserHelpers::calculateAccept(nonce)); } void parse_http_request(char* start, size_t size, HTTPParser* parser) diff --git a/Framework/Core/src/HTTPParser.h b/Framework/Core/src/HTTPParser.h index b4d92393ca5c9..a3253c7ca3d39 100644 --- a/Framework/Core/src/HTTPParser.h +++ b/Framework/Core/src/HTTPParser.h @@ -125,7 +125,8 @@ std::string encode_websocket_handshake_request(const char* path, const char* pro /// Encodes the server reply for a given websocket connection /// @a nonce the nonce of the request. -std::string encode_websocket_handshake_reply(char const* nonce); +/// @a protocol the websocket subprotocol to confirm (optional) +std::string encode_websocket_handshake_reply(char const* nonce, char const* protocol = ""); /// Encodes the buffer @a src which is @a size long to a number of buffers suitable to be sent via libuv. /// If @a binary is provided the binary bit is set.