-
Notifications
You must be signed in to change notification settings - Fork 299
fix(proxy): strip transfer-encoding header from proxied response
#1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughResponse header handling in the proxy was changed to also omit the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
test/proxy.test.ts (1)
171-191: Test name vs. assertions – consider tightening or clarifyingThe new test is useful as a smoke test (custom header preserved, body proxied), but it doesn’t currently assert that any hop‑by‑hop header (e.g.
transfer-encoding) is actually stripped, despite the test name.If the test harness makes it feasible across runtimes, consider also asserting that
transfer-encodingis absent from the proxied response (by setting it on the upstream and checkingres.headers.has("transfer-encoding") === false), or alternatively tweak the test description to better reflect what is being asserted.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/utils/proxy.ts(1 hunks)test/proxy.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/proxy.test.ts (1)
src/utils/proxy.ts (1)
proxyRequest(27-61)
🔇 Additional comments (1)
src/utils/proxy.ts (1)
90-105: Strippingtransfer-encodinghere is correct and consistentSkipping
transfer-encodingalongsidecontent-encodingandcontent-lengthaligns with HTTP hop‑by‑hop semantics and avoids double chunking when re-wrapping the response. The change is minimal, scoped, and looks correct.
When proxying requests, the transfer-encoding header from the upstream response was being passed through to the final response. This caused issues with Bun runtime behind reverse proxies (Caddy, NGINX) where the 502 errors occurred because of conflicting transfer-encoding handling. The Response object handles its own chunked encoding when streaming, so passing through the upstream's transfer-encoding header creates conflicts. This is consistent with the existing approach for content-encoding and content-length headers. Fixes h3js#1246
7dd54fa to
3b87cc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
test/proxy.test.ts (1)
192-217: LGTM! Test correctly validates the transfer-encoding fix.The test appropriately verifies that the
transfer-encodingheader is stripped from proxied responses while preserving other headers and the response body. The web-only restriction is well-justified given the runtime-specific nature of the bug.Optional consideration: If the proxy implementation filters other hop-by-hop headers beyond
transfer-encoding(e.g.,Connection,Keep-Alive,TE,Trailers), you might consider adding test cases for those headers to ensure comprehensive coverage of the filtering logic.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/utils/proxy.ts(1 hunks)test/proxy.test.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/utils/proxy.ts
🧰 Additional context used
🧬 Code graph analysis (1)
test/proxy.test.ts (2)
src/utils/proxy.ts (1)
proxyRequest(27-61)src/event.ts (1)
res(78-80)
🔇 Additional comments (1)
test/proxy.test.ts (1)
171-190: LGTM! Good baseline test for header preservation.This test appropriately verifies that custom headers are preserved during proxying, serving as a regression check to ensure the transfer-encoding fix doesn't inadvertently filter other headers.
pi0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ❤️
transfer-encoding header from proxied response
Summary
This PR fixes #1246 where
proxyRequestdoes not work correctly with Bun runtime behind reverse proxies (Caddy, NGINX), resulting in 502 errors.Problem
When using
proxyRequestwith Bun behind a reverse proxy:Root Cause
The
proxy()function was not filtering out thetransfer-encodingheader from the upstream response. When the upstream returnstransfer-encoding: chunked, this header was being passed through to the final response.Since the Response object handles its own chunked encoding when streaming, passing through the upstream's
transfer-encodingheader creates conflicts. This is especially problematic with Bun's server implementation and reverse proxies.Solution
Added
transfer-encodingto the list of headers to filter out inproxy(), consistent with the existing approach forcontent-encodingandcontent-lengthheaders.Test Plan
Related
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.