Skip to content

Disable automatic gzip compression to fix SSE streaming#1967

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/open-router-4c39baf4
Mar 7, 2026
Merged

Disable automatic gzip compression to fix SSE streaming#1967
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/open-router-4c39baf4

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 6, 2026

Go's default HTTP transport adds Accept-Encoding: gzip and transparently decompresses responses. This is incompatible with SSE streaming because gzip requires buffering the complete payload before decompression, causing unexpected end of JSON input errors with providers like OpenRouter.

Changes

  • Clone the default transport with DisableCompression=true in NewHTTPClient, using a safe type assertion with graceful fallback
  • Consolidate header tests into a single table-driven test with a shared doRequest helper

Fixes #1956

@dgageot dgageot requested a review from a team as a code owner March 6, 2026 11:58
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

Review Summary

Assessment: 🟡 NEEDS ATTENTION

The PR successfully addresses the SSE streaming issue by disabling automatic gzip compression. However, there is one notable concern:

Issue Found:

  • 1 MEDIUM severity: Silent fallback behavior when type assertion fails could leave gzip compression enabled in edge cases

The implementation is mostly sound. The type assertion fallback provides graceful degradation but silently defeats the purpose of the fix in scenarios where http.DefaultTransport has been replaced (e.g., in test environments). Consider adding error handling or using a fresh transport to ensure compression is always disabled.

Findings

1 finding requires attention.

Go's default HTTP transport adds Accept-Encoding: gzip and transparently
decompresses responses. This is incompatible with SSE streaming because
gzip requires buffering the complete payload before decompression,
causing "unexpected end of JSON input" errors with providers like
OpenRouter.

Clone the default transport with DisableCompression=true in
NewHTTPClient, and consolidate the header tests into a single
table-driven test with a shared helper.

Fixes docker#1956

Assisted-By: cagent
@dgageot dgageot force-pushed the board/open-router-4c39baf4 branch from 2d92b01 to 292ec9d Compare March 6, 2026 12:18
@dgageot dgageot merged commit 61e1e90 into docker:main Mar 7, 2026
5 checks passed
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.

OpenRouter Custom Provider Fails with "unexpected end of JSON input"

2 participants