Skip to content

fix #258: detect text streams without Transfer-Encoding (HTTP/2)#259

Open
NeilTheFisher wants to merge 1 commit into
elysiajs:mainfrom
NeilTheFisher:fix/streaming-detection-http2
Open

fix #258: detect text streams without Transfer-Encoding (HTTP/2)#259
NeilTheFisher wants to merge 1 commit into
elysiajs:mainfrom
NeilTheFisher:fix/streaming-detection-http2

Conversation

@NeilTheFisher
Copy link
Copy Markdown

@NeilTheFisher NeilTheFisher commented Apr 18, 2026

Closes #258.

Transfer-Encoding: chunked is forbidden in HTTP/2 (RFC 7540 §8.1.2.2) and stripped by reverse proxies on h1→h2. The detection added in #213 requires that header, so any plain-text streaming route hangs forever when served behind Traefik / nginx / Caddy / Cloudflare with HTTPS. Eden falls into await response.text() and a while (true) generator never resolves.

The chunked clause is also redundant — chunked and Content-Length are mutually exclusive (RFC 7230 §3.3.1), so any HTTP/1.1 chunked response already satisfies the existing !has('content-length') check. Dropping the chunked clause keeps h1 working and fixes h2.

Does not regress #213

A non-streaming text/plain response continues to be buffered because it carries Content-Length. The new test still buffers text/plain when Content-Length is present covers this.

Tests

Three new tests in Treaty2 - HTTP/2 streaming detection (#258):

  1. text/plain + no Transfer-Encoding → streams (the h2 case; fails on main, passes here)
  2. text/plain + Transfer-Encoding: chunked → still streams (h1 regression guard)
  3. text/plain + Content-Length → buffers (Eden doesn't parse response as streamingResponse for chunked encoding #213 regression guard)

Verified: with the fix all 3 pass. Without it, test 1 fails with expected "function" Received: "undefined" (data isn't async-iterable). Full suite stays at 5 pre-existing unrelated WebSocket failures (same on main).

Possibly related

#255 / #256 fix non-SSE chunk yield semantics (chunks weren't emitting until end). Both fixes are needed for h2 plain-text streams to work end-to-end client-side, but they address different layers (parsing vs. detection) and don't conflict.

Summary by CodeRabbit

  • Bug Fixes

    • Improved HTTP streaming detection for text responses. The library now correctly identifies and handles text responses without explicit Content-Length headers, enabling proper streaming support in HTTP/2 and reverse proxy scenarios.
  • Tests

    • Added comprehensive tests validating streaming detection behavior for various text response configurations.

…TTP/2)

The streaming detection added in elysiajs#213 keys off Transfer-Encoding: chunked,
which is forbidden in HTTP/2 (RFC 7540 §8.1.2.2) and stripped by reverse
proxies (Traefik, nginx, Caddy, Cloudflare) when downgrading h1 to h2. The
response still streams over HTTP/2 DATA frames, but treaty falls into
await response.text() and hangs on long-lived generators.

Drop the chunked clause. Per RFC 7230 §3.3.1 chunked and Content-Length are
mutually exclusive, so any HTTP/1.1 chunked response already satisfies the
remaining !has('content-length') check. h1 behavior is unchanged; h2
streaming now works.

Closes elysiajs#258
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Walkthrough

Relaxes HTTP streaming detection for text/* responses by removing the transfer-encoding: chunked requirement. Non-streaming text responses with Content-Length are still buffered normally; this fix allows HTTP/2 proxies (which strip the chunked header) to properly stream plain-text async generators. ✧

Changes

Cohort / File(s) Summary
Streaming Detection Logic
src/treaty2/index.ts
Removed transfer-encoding: chunked check from text response streaming gate. Now treats any text/* response lacking content-length as streamable, accounting for HTTP/2's prohibition on chunked headers.
Streaming Detection Tests
test/treaty2.test.ts
Added comprehensive test suite covering three scenarios: streamed text/plain without Transfer-Encoding (HTTP/2 reverse proxy case), streamed text/plain with chunked header (HTTP/1.1 direct case), and buffered text/plain with explicit Content-Length.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

Chunked headers vanish in the h2 haze~
Your streaming text now works through every maze ♡✧
No more hanging, teasing proxy plays!
— Eden finally caught your tricks, how dull… (´•ω•̥`)

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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.
Linked Issues check ✅ Passed The PR fully addresses issue #258 by removing the Transfer-Encoding: chunked check, adding three comprehensive regression tests, and preserving Content-Length buffering behavior.
Out of Scope Changes check ✅ Passed All changes in treaty2/index.ts and the test file are directly scoped to the HTTP/2 streaming detection fix; no unrelated modifications are present.
Title check ✅ Passed The title clearly and specifically summarizes the main change: removing the Transfer-Encoding requirement from text stream detection to support HTTP/2, which is exactly what the changeset accomplishes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@NeilTheFisher NeilTheFisher changed the title fix(treaty2): detect text streams without Transfer-Encoding (HTTP/2) fix #258: detect text streams without Transfer-Encoding (HTTP/2) Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

treaty2: text/plain streams aren't detected behind HTTP/2 reverse proxies

2 participants