debug-ito / AnyEvent-WebSocket-Server

WebSocket server for AnyEvent
7 stars 2 forks source link

Impossible to set subprotocol #1

Closed mephinet closed 9 years ago

mephinet commented 9 years ago

I'm rather new to async websocket programming, so I might miss the obvious - but I wasn't able to find a way to set the Sec-WebSocket-Protocol of the Response sent by AnyEvent::WebSocket::Server. The establish* methods of the Server implementation use Protocol::WebSocket::Handshake::Server to create the HTTP 101 response for the received request. However, they do not allow for the application to influence the creation of the Protocol::WebSocket::Response - so the user cannot set the "subprotocol" field.

debug-ito commented 9 years ago

It's not related to async operation, so you are right. Currently we have no way to fine-tune the response. Unfortunately, Protocol::WebSocket module family does not expose so many public (and well-documented) methods, so there are few things we can do.

If you really want this feature (i.e., setting sub-protocol in the response), I can make a necessary pull-request to vti/protocol-websocket. After the new version of Protocol::WebSocket is released, I can implement the feature.

debug-ito commented 9 years ago

Oops. I found Protocol::WebSocket::Handshake has res method and it's documented.

OK, I'll try using this to make an interface to customize the request..

mephinet commented 9 years ago

That would be great! :+1:

debug-ito commented 9 years ago

Released version 0.06.

mephinet commented 9 years ago

Thanks a lot, I'll give it a try!

mephinet commented 9 years ago

Perfect, specifying a handshake callback allows me to call subprotocol on the response object! Thanks again.

debug-ito commented 9 years ago

I'm glad to hear that. Thanks for reporting.