Skip to content

fix(httpserver): use chunked transfer encoding for SSE streaming responses#101

Merged
Oaklight merged 1 commit into
masterfrom
fix/httpserver-sse-chunked-encoding
Jun 12, 2026
Merged

fix(httpserver): use chunked transfer encoding for SSE streaming responses#101
Oaklight merged 1 commit into
masterfrom
fix/httpserver-sse-chunked-encoding

Conversation

@Oaklight

Copy link
Copy Markdown
Owner

Summary

  • SSE (text/event-stream) streaming responses now use Transfer-Encoding: chunked like all other streaming responses, instead of flushing raw bytes with Connection: close
  • Fixes proxy compatibility issues with Go's httputil.ReverseProxy (used by NPS, and other Go-based reverse proxies) that misparse raw SSE data as chunked encoding
  • Matches behavior of production SSE servers (OpenAI, Anthropic APIs)

Context

Discovered when running llm-rosetta-gateway behind an NPS tunnel. NPS logs showed repeated errors:

httputil: ReverseProxy read error during body copy: invalid byte in chunk length
httputil: ReverseProxy read error during body copy: invalid CR in chunked line

The old approach (no Content-Length, no Transfer-Encoding, rely on connection close) is valid per HTTP/1.1 spec but incompatible with proxies that re-frame the response body.

Test plan

  • All 58 existing httpserver tests pass (including SSE and chunked streaming tests)
  • ruff check + ruff format clean
  • Pre-commit hooks pass

Closes #100

…onses

SSE responses previously skipped Transfer-Encoding: chunked and relied
on Connection: close to signal body end.  While valid per HTTP/1.1 spec,
this breaks intermediate proxies (notably Go's httputil.ReverseProxy
used by NPS) that expect either Content-Length or chunked framing —
they misparse the raw SSE data as chunked encoding, producing errors
like "invalid byte in chunk length".

Unify all StreamingResponse output to use chunked encoding, matching
the behavior of production SSE servers (OpenAI, Anthropic APIs).

Closes #100
@Oaklight Oaklight self-assigned this Jun 12, 2026
@Oaklight Oaklight merged commit fcd0921 into master Jun 12, 2026
6 checks passed
@Oaklight Oaklight deleted the fix/httpserver-sse-chunked-encoding branch June 12, 2026 20:49
Oaklight added a commit to Oaklight/llm-rosetta that referenced this pull request Jun 12, 2026
Re-vendor httpserver from zerodep to pick up the fix for SSE
streaming responses not using Transfer-Encoding: chunked.  This
caused Go-based reverse proxies (NPS httputil.ReverseProxy) to
misparse SSE data, producing "invalid byte in chunk length" errors
and intermittent ConnectionRefused under concurrent load.

Upstream: Oaklight/zerodep#101
Closes #274
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.

httpserver: SSE streaming should use chunked transfer encoding for proxy compatibility

1 participant