websocket icon indicating copy to clipboard operation
websocket copied to clipboard

Improve upgrader documentation regarding protocols

Open garyburd opened this issue 5 years ago • 4 comments

Points to cover

  • An application can handle subprotocol negotiation on its own by setting the Sec-Websocket-Protocol response header. The Subprotocols(r *http.Request) []string function is helpful here.
  • Set u.Subprotocols for builtin subprotocol negotiation. Builtin negotiation overrides a subprotocol specified in the response header (it would have been better to return an error, but it's too late to change that).
  • Builtin negotiation uses first match in u.Subprotocols. If there's no match, then no protocol is negotiated.

garyburd avatar Jul 31 '18 18:07 garyburd

Hi! Could I contribute with it =?

marti1125 avatar Sep 14 '19 16:09 marti1125

Hi, @marti1125 yes absolutely! Documentation contributions are always welcome assuming they're clear and concise; my vote, feel free to open a pull request if you have documentation you believe would be useful.

IngCr3at1on avatar Sep 14 '19 16:09 IngCr3at1on

I am trying to understand subprotocols using client/server example

I just modify https://github.com/gorilla/websocket/blob/master/examples/echo/server.go#L23

c, err := upgrader.Upgrade(w, r, r.Header)

in the terminal show upgrade:websocket: application specific 'Sec-WebSocket-Extensions' headers are unsupported

marti1125 avatar Sep 15 '19 19:09 marti1125

@marti1125 It looks like you added a Sec-WebSocket-Extensions header, but that header is unrelated to subprotocols. Did you you intend to add a Sec-Websocket-Protocol instead?

ghost avatar Oct 02 '19 21:10 ghost