slact / nchan

Fast, horizontally scalable, multiprocess pub/sub queuing server and proxy for HTTP, long-polling, Websockets and EventSource (SSE), powered by Nginx.
https://nchan.io/
Other
2.99k stars 292 forks source link

Sec-WebSocket-Protocol #648

Closed vthorsell closed 1 year ago

vthorsell commented 1 year ago

Hi, is it possible to define a reply to a new subscriber with the same subprotocol used in the connection Sec-WebSocket-Protocol?

i.e. I have certain connections that demand in the reply/authorize that Sec-WebSocket-Protocol is set to the same value as provided in the request, nothing else would need to be changed that just being able to reply with either specified reply or the same replay as used in the connection.

slact commented 1 year ago

You should be able to do this with the nginx header module:

location /ws_subscriber {
  nchan_subscriber;
  nchan_channel_id foo;
  add_header Sec-WebSocket-Protocol "$http_sec_websocket_protocol";
}

(I haven't tested it, but it should work. please let me know if it does not.)