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

[bug] Websocket subprotocol is not chosen on client preferance #4

Open
tebruno99 opened this issue Dec 12, 2022 · 0 comments
Open
Labels
bug Something isn't working waiting on new maintainer

Comments

@tebruno99
Copy link

From websocket created by KSDaemon: gorilla#822

Describe the bug

From the Websocket RFC6455:

For client side:

|Sec-WebSocket-Protocol| header field, with a list of values indicating which protocols the client would like to speak, ordered by preference.

And for server side:

Either a single value representing the subprotocol the server is ready to use or null. The value chosen MUST be derived from the client's handshake, specifically by selecting one of the values from the |Sec-WebSocket-Protocol| field that the server is willing to use for this connection (if any).

So if the client provides a few options for subprotocol. The server should choose the first one it supports.

Right now, if client provides a few options, lib choose the first one it supports (and not the first one from the client).

e.g. So if the client sends Sec-WebSocket-Protocol: wamp.2.cbor, wamp.2,json and server supports wamp.2,json, wamp.2.cbor then wamp.2,json will be chosen but not wamp.2.cbor as it should be.

A clear and concise description of what the bug is.

Lib version: all :)

Code Snippets
The problem is in server.go: selectSubprotocol func:

		clientProtocols := Subprotocols(r)
		for _, serverProtocol := range u.Subprotocols {
			for _, clientProtocol := range clientProtocols {
				if clientProtocol == serverProtocol {
					return clientProtocol
				}
			}
		}

should be changed to:

        clientProtocols := Subprotocols(r)
        for _, clientProtocol := range clientProtocols {
            for _, serverProtocol := range u.Subprotocols {
                if clientProtocol == serverProtocol {
                    return clientProtocol
                }
            }
        }
@tebruno99 tebruno99 added bug Something isn't working waiting on new maintainer labels Dec 12, 2022
tebruno99 added a commit that referenced this issue Dec 13, 2022
Fixes subprotocol selection (aling with rfc6455) fixes #4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting on new maintainer
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant