I misunderstood your original question @marti1125, now that I understand you were asking a related but still slightly separate question I've created a new issue for this using the 'reference in new issue' function.
Original comment is as follows:
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
_Originally posted by @marti1125 in https://github.com/gorilla/websocket/issues/404#issuecomment-531591181_
As noted in the OP I moved this over from the original issue to keep that issue on task. To answer the question itself; I believe (after a bit of reading) that this is really just related to the included (experimental) implementation of RFC7692.
To that end have a look at https://godoc.org/github.com/gorilla/websocket#hdr-Compression_EXPERIMENTAL
You should be able to enable compression via boolean there, rather than attaching the header yourself.
@elithrar This issue has been resolved and can be closed.
@nhooyr may I know in which version has been solved?
I'm using v1.4.2 and when I pass the r.Header I get the same error as @IngCr3at1on mentioned
conn, err := upgrader.Upgrade(w, r, r.Header)
websocket: application specific 'Sec-WebSocket-Extensions' headers are unsupported
websocket: application specific 'Sec-WebSocket-Extensions' headers are unsupported
So this header error means you're setting Sec-WebSocket-Extensions before calling Upgrade. You just need to stop doing that as you cannot use a custom extension (one that isn't RFC 7692 compression).
You just need to stop doing that
stop passing r.Header in the Upgrade() do you mean?
thanks for the reference link. I can see
- Extension Negotiation
To offer use of a PMCE, a client MUST include the extension name of
the PMCE in the "Sec-WebSocket-Extensions" header field of its
opening handshake of the WebSocket connection.
so not sure when you said
you cannot use a custom extension
This is what I get as a response and the request on the browser. if I pass r.Header to the Upgrade().

btw, I'm using the gorilla chat example for the client-side exactly and no changes on its js code. on the other hand on the server, I'm not sending any custom or manual header as a response to the client's request.
So to avoid this error in order to just get the result I can validate the origin manually which I don't this this is the production level / proper solution!
var Upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
if r.Header.Get("Origin") == "http://localhost:9090" { // <=====
return true
}
return false
},
}
May I ask what is proper / production level the solution?
Also, in the example, I can see they pass nil as the responseHeader. so if we need to pass nil, why the function has the responseHeader parameter?
func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error)
I think you're confused on what responseHeader is for. Please see the docs on Upgrade and inspect its source code.