5
votes

How do I set Sec-WebSocket-Protocol to the response header in phoenix websocket?

I have tried Plugs to add the header field to the conn object but it seems like somewhere along the way it has been dropped. The other option I tried was to create a custom websocket by importing Phoenix.Transport.Websocket but ended up with no success.

1
This is exactly the same thing i am trying to do!!!! Did you end up finding an answer?Acidic9
Sorry @Acidic, I did not find an answer yet, my plan is to dig into the socket layer and find out what's going on.aoeking
github.com/absinthe-graphql/absinthe/issues/… I made a github issue and using the link he provided I managed to get it to work. Not sure if its the same issue as yours though but that has solved it for me in this case.Acidic9
Thanks @Acidic, I ll check this out and let you know the resultsaoeking

1 Answers

0
votes

Support for this is under way in phoenix, see pull request #3444. If you really need to try it out, consider cherry-picking the patch on top of your fork of phoenix, or using phoenix from PR author's branch directly.

The header will be set automatically if it was passed by client. Per added docs:

If the sec-websocket-protocol header matches the allowed subprotocol, it will put sec-websocket-protocol response header and return the given connection.

If no sec-websocket-protocol header was sent it will return the given connection.