Skip to content

Conversation

pimterry
Copy link
Member

@pimterry pimterry commented Sep 9, 2025

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 an upgrade handler and all upgrade attempts would always effectively succeed, going straight to the upgrade 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.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels Sep 9, 2025
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.
@pimterry pimterry force-pushed the http-upgrade-callback branch from 27368d0 to 7468355 Compare September 9, 2025 12:37
@pimterry pimterry added the semver-minor PRs that contain new features and should be released in the next minor version. label Sep 9, 2025
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.29%. Comparing base (73b5022) to head (1c43426).
⚠️ Report is 69 commits behind head on main.

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     
Files with missing lines Coverage Δ
lib/_http_server.js 97.38% <100.00%> (+0.43%) ⬆️

... and 76 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 11, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 11, 2025
@nodejs-github-bot
Copy link
Collaborator

@pimterry pimterry added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Sep 12, 2025
@mykola-mokhnach
Copy link

@pimterry Unfortunately I don't have permission to approve the PR, otherwise LGTM.

@pimterry pimterry added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Sep 17, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 17, 2025
@nodejs-github-bot
Copy link
Collaborator

@pimterry pimterry added the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 17, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 17, 2025
@nodejs-github-bot nodejs-github-bot merged commit 65bee02 into nodejs:main Sep 17, 2025
68 of 69 checks passed
@nodejs-github-bot
Copy link
Collaborator

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve HTTP server 'upgrade' event generation logic
4 participants