Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to apply subprotocol parameter #31

Open
abitcyanine opened this issue Dec 10, 2021 · 2 comments
Open

How to apply subprotocol parameter #31

abitcyanine opened this issue Dec 10, 2021 · 2 comments

Comments

@abitcyanine
Copy link

Our old server applies the subprotocol parameter on websocket. Now we need to use oatpp in the server. How to apply the subprotocol parameter?

@lganzzzo
Copy link
Member

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
Copy link
Author

OK, I'll try the method you provided. Thank you for your reply

@lganzzzo lganzzzo mentioned this issue Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants