-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
http: add shouldUpgradeCallback to let servers control HTTP upgrades #59824
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
Merged
nodejs-github-bot
merged 2 commits into
nodejs:main
from
pimterry:http-upgrade-callback
Sep 17, 2025
Merged
http: add shouldUpgradeCallback to let servers control HTTP upgrades #59824
nodejs-github-bot
merged 2 commits into
nodejs:main
from
pimterry:http-upgrade-callback
Sep 17, 2025
+210
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Review requested:
|
Previously, you could either add no 'upgrade' event handler, in which case all upgrades were ignored, or add an 'upgrade' handler and all upgrade attempts would effectively succeed and skip normal request handling. This change adds a new shouldUpgradeCallback option to HTTP servers, which receives the request details and returns a boolean that controls whether the request should be upgraded.
27368d0
to
7468355
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59824 +/- ##
==========================================
+ Coverage 88.26% 88.29% +0.03%
==========================================
Files 701 702 +1
Lines 206644 206774 +130
Branches 39737 39780 +43
==========================================
+ Hits 182386 182571 +185
+ Misses 16279 16218 -61
- Partials 7979 7985 +6
🚀 New features to boost your workflow:
|
3 tasks
lpinca
approved these changes
Sep 11, 2025
@pimterry Unfortunately I don't have permission to approve the PR, otherwise LGTM. |
lpinca
approved these changes
Sep 12, 2025
Landed in 65bee02 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
author ready
PRs that have at least one approval, no pending requests for changes, and a CI started.
commit-queue-squash
Add this label to instruct the Commit Queue to squash all the PR commits into the first one.
http
Issues or PRs related to the http subsystem.
needs-ci
PRs that need a full CI run.
semver-minor
PRs that contain new features and should be released in the next minor version.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #57054
Previously, you could either add no
upgrade
event handler to your HTTP server, in which case all HTTP upgrade requests were ignored, or you could add anupgrade
handler and all upgrade attempts would always effectively succeed, going straight to theupgrade
event and skipping normal request handling.That can be inflexible, as there's plenty of cases where you want to support just upgrading specific requests (most commonly, specific protocols - e.g. upgrading to support websockets but not h2c).
This change adds a new
shouldUpgradeCallback
option to HTTP servers, which receives the request details and returns a boolean that controls whether the request should be upgraded. Existing behaviour isn't changed, by making the default option value() => server.listenerCount('upgrade') > 0
.