Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] why are 'Sec-WebSocket-Extensions' headers not supported by upgrader. #540

Closed
IngCr3at1on opened this issue Sep 17, 2019 · 6 comments
Labels

Comments

@IngCr3at1on
Copy link

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 #404 (comment)

@IngCr3at1on
Copy link
Author

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.

@IngCr3at1on IngCr3at1on changed the title [question] why are 'Sec'WebSocket-Extensions' headers not supported by upgrader. [question] why are 'Sec-WebSocket-Extensions' headers not supported by upgrader. Sep 17, 2019
@nhooyr
Copy link

nhooyr commented Sep 30, 2019

@elithrar This issue has been resolved and can be closed.

@ghost
Copy link

ghost commented Dec 8, 2020

@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

@nhooyr
Copy link

nhooyr commented Dec 9, 2020

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).

@ghost
Copy link

ghost commented Dec 9, 2020

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

  1. 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().
image


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)

@nhooyr
Copy link

nhooyr commented Dec 9, 2020

I think you're confused on what responseHeader is for. Please see the docs on Upgrade and inspect its source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants