fix(ext/node): emit "connect" event on http.Server for CONNECT requests#32599
Merged
bartlomieju merged 4 commits intomainfrom Mar 12, 2026
Merged
fix(ext/node): emit "connect" event on http.Server for CONNECT requests#32599bartlomieju merged 4 commits intomainfrom
bartlomieju merged 4 commits intomainfrom
Conversation
Fixes a crash where `testEnabled is not a function` is thrown during bootstrap when internal stream code triggers debug logging before `initializeDebugEnv()` has been called. This occurs when stdin is unavailable, such as in compiled binaries run as Windows services (via nssm) or processes detached with nohup/disown. Initialize `testEnabled` and `debugImpls` with safe defaults (`() => false` and empty object) so early calls to `debuglog()` gracefully disable debug logging instead of crashing. Closes #24208 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deno's node:http Server polyfill never emitted the "connect" event for HTTP CONNECT method requests, causing HTTP proxy libraries (e.g. proxy-chain, used by Crawlee) to silently drop tunnel requests. This made Playwright/Crawlee's browser unable to navigate (net::ERR_TIMED_OUT) since Chrome's CONNECT requests to the local proxy were never handled. - Handle CONNECT method in ServerImpl._serve() by upgrading to a raw socket and emitting "connect" with (req, socket, head), matching Node.js behavior - Strip "http://" prefix from CONNECT request URLs to return authority form (host:port) as Node.js does - Relax UpgradeStream status code check to accept both 101 (WebSocket) and 200 (CONNECT tunnel) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
Author
|
Related #26925 |
kajukitli
reviewed
Mar 10, 2026
Contributor
kajukitli
left a comment
There was a problem hiding this comment.
The PR correctly implements CONNECT request handling for http.Server, enabling HTTP proxy functionality. However, there's a minor Node.js API compatibility gap: the head parameter passed to the 'connect' event is hardcoded to an empty Buffer rather than containing any trailing data received after the CONNECT headers in the same TCP packet. While this doesn't break typical proxy use cases (data remains readable from the socket), it's a deviation from Node.js behavior that could affect proxies expecting pipelined data in the head buffer.
littledivy
approved these changes
Mar 12, 2026
Member
littledivy
left a comment
There was a problem hiding this comment.
LGTM, pending the minor nit
Add a dedicated CONNECT upgrade path that sends the 200 response via hyper, awaits the upgrade, and captures any trailing bytes (data pipelined after the CONNECT request headers). These bytes are passed as the `head` parameter to the "connect" event, matching Node.js behavior. The new UpgradeStream `ConsumeResponse` write state absorbs the redundant HTTP response the application writes through the socket (since hyper already sent 200), then switches to raw network mode. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
# Conflicts: # ext/http/http_next.rs # ext/node/polyfills/http.ts
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
node:httpServer polyfill never emitted the"connect"event for HTTP CONNECT method requestsproxy-chain, used by Crawlee/Playwright) that rely on this event to handle tunnel requests--proxy-serversends CONNECT requests to establish HTTPS tunnels — without the event, these were silently dropped, causingnet::ERR_TIMED_OUTChanges
ServerImpl._serve()by upgrading to a raw socket and emitting"connect"with(req, socket, head), matching Node.js behaviorhttp://prefix from CONNECT request URLs to return authority form (host:port) as Node.js doesUpgradeStreamstatus code check inhttp_next.rsto accept both101(WebSocket upgrade) and200(CONNECT tunnel)Test plan
tests/specs/node/http_server_connect_eventverifies full CONNECT tunnel flow (event emission, proxy tunnel establishment, data passthrough)🤖 Generated with Claude Code