fix(http): properly handle pipelined data in CONNECT requests (#25938)

Fixes #25862

### What does this PR do?

When a client sends pipelined data immediately after CONNECT request
headers in the same TCP segment, Bun now properly delivers this data to
the `head` parameter of the 'connect' event handler, matching Node.js
behavior.

This enables compatibility with Cap'n Proto's KJ HTTP library used by
Cloudflare's workerd runtime, which pipelines RPC data after CONNECT.

### How did you verify your code works?
<img width="694" height="612" alt="CleanShot 2026-01-09 at 15 30 22@2x"
src="https://github.com/user-attachments/assets/3ffe840e-1792-429c-8303-d98ac3e6912a"
/>

Tests

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Ciro Spaciari
2026-01-09 19:08:02 -08:00
committed by GitHub
parent 7076a49bb1
commit b610e80ee0
4 changed files with 78 additions and 3 deletions

View File

@@ -474,6 +474,15 @@ static EncodedJSValue NodeHTTPServer__onRequest(
}
args.append(jsBoolean(request->isAncient()));
// Pass pipelined data (head buffer) for Node.js compat (connect/upgrade events)
if (!request->head.empty()) {
JSC::JSUint8Array* headBuffer = WebCore::createBuffer(globalObject, std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(request->head.data()), request->head.size()));
RETURN_IF_EXCEPTION(scope, {});
args.append(headBuffer);
} else {
args.append(jsUndefined());
}
JSValue returnValue = AsyncContextFrame::profiledCall(globalObject, callbackObject, jsUndefined(), args);
RETURN_IF_EXCEPTION(scope, {});