From 74683556864fbd45b2f978015690eb6acc0f41e5 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Tue, 9 Sep 2025 14:34:59 +0200 Subject: [PATCH 1/2] 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. --- doc/api/http.md | 26 ++- lib/_http_server.js | 17 +- .../test-http-upgrade-server-callback.js | 167 ++++++++++++++++++ 3 files changed, 205 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 683dc0fbe4b1e0..d01173798957c2 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).