How to apply subprotocol parameter
abitcyanine opened this issue · comments
abitcyanine commented
Our old server applies the subprotocol parameter on websocket. Now we need to use oatpp in the server. How to apply the subprotocol parameter?
Leonid Stryzhevskyi commented
Hello @abitcyanine ,
oatpp doesn't check for subprotocol and at the moment just ignores it.
So you have to manually add a subprotocol check in the handshake.
Should be something like that:
ENDPOINT("GET", "ws", ws,
HEADER(String, subprotocol, "Sec-WebSocket-Protocol"), //< protocol header
REQUEST(std::shared_ptr<IncomingRequest>, request))
{
/* check subprotocol value */
OATPP_ASSERT_HTTP(subprotocol == "my-subprotocol", Status::CODE_400, "unknown subprotocol")
/* do the handshake */
auto response = oatpp::websocket::Handshaker::serversideHandshake(request->getHeaders(), websocketConnectionHandler);
/* agree on subprotocol */
response->putHeader("Sec-WebSocket-Protocol", "my-subprotocol");
return response;
};
Regards,
Leonid
abitcyanine commented
OK, I'll try the method you provided. Thank you for your reply