Skip to content

fix(proxy): fix content encoding#3

Open
ionmincu wants to merge 1 commit intoa2anet:mainfrom
ionmincu:main
Open

fix(proxy): fix content encoding#3
ionmincu wants to merge 1 commit intoa2anet:mainfrom
ionmincu:main

Conversation

@ionmincu
Copy link

Fix proxy forwarding content-encoding header causing ERR_CONTENT_DECODING_FAILED

Problem

The proxy endpoint (/api/proxy) was forwarding the content-encoding header (e.g. gzip) from the target server's response back to the browser. However, Node.js fetch automatically decompresses the response body when calling response.text(), so the body returned to the browser was already decompressed plaintext.

The browser would see content-encoding: gzip, attempt to decompress the already-decompressed body, and fail with net::ERR_CONTENT_DECODING_FAILED. This surfaced as a generic Failed to fetch / Failed to parse Agent Card JSON error in the UI.

Root Cause

  1. Proxy calls fetch(targetUrl) — target responds with content-encoding: gzip
  2. Proxy calls response.text() — Node.js transparently decompresses the body
  3. Proxy creates a new Response with the decompressed body but forwards the original content-encoding: gzip header
  4. Browser receives response, sees content-encoding: gzip, tries to decompress again — fails

Fix

Strip content-encoding and content-length from forwarded response headers. The body is already decompressed by the time we forward it, so these headers are invalid. The runtime will set correct values automatically.

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.

1 participant