Skip to content

http-transport: cork backpressure, x-forwarded-proto precedence, payload 400, GET Accept - #267

Merged
denny-il merged 3 commits into
mainfrom
dev/http-transport-fixes
Jul 15, 2026
Merged

denny-il merged 3 commits into
mainfrom
dev/http-transport-fixes

Conversation

@denny-il

@denny-il denny-il commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #204, closes #213

  • Chunked-stream backpressure actually engages (runtimes/node.ts): res.cork(cb) returns the response object (always truthy), not write()'s boolean, so the backpressure wait was dead code and uWS buffered every un-drained byte of a streamed response in memory. Beyond the issue's sketch, uWS turned out to honor only the first onWritable registration per response — the old per-wait re-registration could never have worked, and the naive capture-only fix would deadlock on the second backpressure event. The pump now uses a single lazily-registered onWritable handler dispatching drain events to the current waiter, and onAborted wakes a pending waiter so a client disconnect mid-backpressure exits the pump instead of leaking it. Verified against a live uWS server (slow client pauses the source at ~11/100 chunks, resumes to full delivery) plus deterministic unit tests over a scripted response double (two wait/drain cycles, drain with no waiter, abort-while-waiting, drain-then-abort).
  • x-forwarded-proto precedence (runtimes/node.ts): header || tls ? 'https' : 'http' parsed as (header || tls) ? …, so any header value — including http — produced https. The header value now decides when present, falling back to the TLS param.
  • Malformed ?payload= returns 400 (server.ts): the JSON.parse SyntaxError fell into the unknown-error branch and surfaced as 500 InternalServerError; it now maps to BadRequest.
  • GET honors Accept (server.ts): GET responses unconditionally forced the default format; the client's Accept header is now negotiated, falling back to */* only when negotiation fails (tolerating browser-navigation Accept headers).

Summary by CodeRabbit

  • Bug Fixes
    • Improved chunked streaming to better handle backpressure, aborts, and client disconnects without hanging.
    • Correctly derives the request URL protocol when behind proxies by honoring x-forwarded-proto (fallback to listener protocol when missing).
    • Improved Accept negotiation for GET requests, using the client’s Accept when appropriate and safely falling back when unsupported.
    • Invalid JSON in GET payload query parameters now returns HTTP 400 with a clear “Invalid payload” error.
  • Tests
    • Added new Node runtime and server HTTP handler test coverage for protocol selection, streaming backpressure, and chunked write/abort behavior.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6b500ba2-c908-4c93-82e0-0b008f02035a

📥 Commits

Reviewing files that changed from the base of the PR and between 7ddbb19 and 2a2e9b2.

📒 Files selected for processing (2)
  • packages/http-transport/src/runtimes/node.ts
  • packages/http-transport/tests/node-runtime.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/http-transport/tests/node-runtime.spec.ts
  • packages/http-transport/src/runtimes/node.ts

📝 Walkthrough

Walkthrough

The HTTP transport now honors forwarded URL protocols, handles uWS writable backpressure and aborts during chunked streaming, negotiates GET Accept values, and returns bad-request errors for malformed query payloads. Runtime and server tests cover these behaviors.

Changes

HTTP transport behavior

Layer / File(s) Summary
Node runtime protocol and streaming handling
packages/http-transport/src/runtimes/node.ts, packages/http-transport/tests/node-runtime.spec.ts
Forwarded protocols take precedence, writable callbacks coordinate backpressure and aborts, and chunked stream behavior is covered by runtime tests.
Server request negotiation and payload validation
packages/http-transport/src/server.ts, packages/http-transport/tests/server.spec.ts
GET Accept negotiation is preserved when supported, unsupported values fall back to */*, and malformed query payload JSON returns a 400 response.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant NodeRuntime
  participant ReadableStream
  participant UwsResponse
  Client->>NodeRuntime: request with protocol and streamed response
  NodeRuntime->>ReadableStream: read chunk
  NodeRuntime->>UwsResponse: cork and write chunk
  UwsResponse-->>NodeRuntime: backpressure status
  UwsResponse->>NodeRuntime: onWritable
  NodeRuntime->>ReadableStream: resume reading
  UwsResponse->>NodeRuntime: abort response
  NodeRuntime->>ReadableStream: cancel body
Loading

Possibly related issues

  • Issue #207: Adds Node runtime coverage for uWS abort handling and chunked-stream backpressure behavior.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title concisely summarizes the main http-transport fixes covered by the PR.
Linked Issues check ✅ Passed The PR implements the backpressure, x-forwarded-proto, payload, and GET Accept fixes from #204 and #213.
Out of Scope Changes check ✅ Passed The added tests and abort-handling support stay aligned with the linked http-transport fixes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/http-transport-fixes

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/http-transport/src/runtimes/node.ts`:
- Around line 24-26: The streaming response flow must cancel a pending reader
when the client aborts, not only wake waitWritable(). Extend UwsResponse with
the appropriate abort event hook, register it in the stream pump around the
reader.read() loop, and cancel the reader on abort so a stalled read exits and
cleanup completes. Add coverage for an abort occurring while reader.read() is
pending.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8fe32161-027a-4ea1-8c8d-bf4ed55b23bf

📥 Commits

Reviewing files that changed from the base of the PR and between e258b3b and 7ddbb19.

📒 Files selected for processing (4)
  • packages/http-transport/src/runtimes/node.ts
  • packages/http-transport/src/server.ts
  • packages/http-transport/tests/node-runtime.spec.ts
  • packages/http-transport/tests/server.spec.ts

Comment thread packages/http-transport/src/runtimes/node.ts Outdated
@denny-il
denny-il merged commit 6bd6484 into main Jul 15, 2026
5 checks passed
@denny-il
denny-il deleted the dev/http-transport-fixes branch July 15, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant