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

Sec-WebSocket-Protocol header missing in Upgrade response #792

Closed
pitti98 opened this issue May 8, 2023 · 5 comments · Fixed by #798
Closed

Sec-WebSocket-Protocol header missing in Upgrade response #792

pitti98 opened this issue May 8, 2023 · 5 comments · Fixed by #798

Comments

@pitti98
Copy link
Contributor

pitti98 commented May 8, 2023

This causes chrome, and probably other webkit-based browsers, to fail the ws connection with an error 1006.

fix: add a line to the http_reply call in websock_accept()

"Sec-WebSocket-Protocol: sip\r\n"

@sreimers
Copy link
Member

sreimers commented May 8, 2023

Can you provide more details about your patch, at best a complete diff or with file and line number.

@pitti98
Copy link
Contributor Author

pitti98 commented May 8, 2023

Here you go:

diff --git a/src/websock/websock.c b/src/websock/websock.c
index 710f697..6a933af 100644
--- a/src/websock/websock.c
+++ b/src/websock/websock.c
@@ -542,6 +542,7 @@ int websock_accept(struct websock_conn **connp, struct websock *sock,
                         "Upgrade: websocket\r\n"
                         "Connection: Upgrade\r\n"
                         "Sec-WebSocket-Accept: %H\r\n"
+                        "Sec-WebSocket-Protocol: sip\r\n"
                         "\r\n",
                         accept_print, &key->val);
        if (err)

@sreimers
Copy link
Member

sreimers commented May 8, 2023

Proto is not supported currently, I just opened a PR, this introduces a new proto specific api:

websock_accept_proto(connp, "sip",....);

@pitti98
Copy link
Contributor Author

pitti98 commented May 8, 2023

As far as I see, the Sec-WebSocket-Protocol header is mandatory in both the request and the 101 response, so the functions without a protocol will never be valid, right?

Edit:
Hmm, apparently the original rfc6455 says both are optional.

The source I found that mentions the header is
https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism
which says:
"The first one that is supported by the server will be selected and returned by the server in a Sec-WebSocket-Protocol header included in the response."

This sounded like it is not optional.

But apparently it is. So nevermind.

@pitti98
Copy link
Contributor Author

pitti98 commented May 8, 2023

That pull request just adds new functions, but transp.c/http_req_handler() needs to call the new one or it still won't work.

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

Successfully merging a pull request may close this issue.

2 participants