Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Framework/Core/src/DPLWebSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion Framework/Core/src/HTTPParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ std::string encode_websocket_handshake_reply(char const* nonce)
"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)
Expand Down
3 changes: 2 additions & 1 deletion Framework/Core/src/HTTPParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down