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

upgrade hook runs even on non-websocket upgrade requests #120

Closed
1 task done
eltigerchino opened this issue Feb 6, 2025 · 2 comments · Fixed by #131
Closed
1 task done

upgrade hook runs even on non-websocket upgrade requests #120

eltigerchino opened this issue Feb 6, 2025 · 2 comments · Fixed by #131
Labels
documentation Improvements or additions to documentation

Comments

@eltigerchino
Copy link
Contributor

eltigerchino commented Feb 6, 2025

Describe the change

Currently, the upgrade hook runs for any upgrade request, even non-websocket ones, but returns 400 Invalid Upgrade header afterwards if Upgrade: websocket isn't present. This is because the Node adapter documentation suggests attaching the upgrade handler such as below:

// this handles all upgrade requests, not just websocket ones
server.on("upgrade", ws.handleUpgrade);

Ideally, the crossws upgrade hook only runs if the header Upgrade: websocket exists since the upgrade hook has probably been programmed with only websocket upgrade requests in mind.

Alternatively, we could change the documentation to suggest handling this case ourselves (not so ideal):

server.on("upgrade", (req, socket, head) => {
  if (req.headers.upgrade === 'websocket') {
    ws.handleUpgrade(req, socket, head);
    return;
  }
  // TODO: reject connection
});

URLs

No response

Additional information

  • Would you be willing to help?
@eltigerchino eltigerchino added the documentation Improvements or additions to documentation label Feb 6, 2025
@pi0
Copy link
Member

pi0 commented Feb 6, 2025

Thats a good pooint and idea! Indeed documentation should avice explicit value check.

I have to check implementation bug i guess for other adapters we also ask users to check header manually.

@LukeHagar
Copy link
Collaborator

LukeHagar commented Feb 10, 2025

This seems like a good thing to add to the docs as stated, since the usage is not the same across adapters, and the manual header check is required for other implementations

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

Successfully merging a pull request may close this issue.

3 participants