From 7aec53b607fcd1b07d0675cf919bb131c0905ba1 Mon Sep 17 00:00:00 2001 From: Tim Perry <1526883+pimterry@users.noreply.github.com> Date: Wed, 17 Sep 2025 17:14:01 +0200 Subject: [PATCH] http: add shouldUpgradeCallback to let servers control HTTP upgrades 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. PR-URL: https://github.com/nodejs/node/pull/59824 Reviewed-By: Luigi Pinca --- doc/api/http.md | 31 +++- lib/_http_server.js | 17 +- .../test-http-upgrade-server-callback.js | 167 ++++++++++++++++++ 3 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-http-upgrade-server-callback.js diff --git a/doc/api/http.md b/doc/api/http.md index 4193a1e9d1e..56031ac73f4 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1671,6 +1671,11 @@ per connection (in the case of HTTP Keep-Alive connections).