Skip to content

fix: strip Accept-Encoding from proxied requests#5

Merged
JaredHatfield merged 3 commits into
mainfrom
fix/strip-accept-encoding-proxy
May 21, 2026
Merged

fix: strip Accept-Encoding from proxied requests#5
JaredHatfield merged 3 commits into
mainfrom
fix/strip-accept-encoding-proxy

Conversation

@JaredHatfield
Copy link
Copy Markdown
Member

Strip Accept-Encoding from forwarded request headers so Go's http.Transport manages gzip compression transparently for the proxy→upstream leg.

Problem: When clients send Accept-Encoding: gzip, the proxy forwards it to the upstream. The upstream responds with a compressed body, but the proxy's JSON parsing, model rewriting, and usage tracking all expect uncompressed bytes — causing silent failures.

Fix: Skip Accept-Encoding in copyRequestHeaders. Go's http.Transport then adds its own Accept-Encoding: gzip, decompresses the response body automatically, and strips Content-Encoding/ Content-Length before the proxy reads it. The upstream still gets compressed responses (bandwinth efficient), but the proxy always operates on plain JSON.

Works for both streaming (SSE) and non-streaming responses since gzip decompression is incremental.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts request header forwarding in the proxy so that Accept-Encoding is not forwarded upstream, allowing Go’s http.Transport to manage gzip transparently and ensuring the proxy always reads uncompressed JSON for parsing/rewriting/usage tracking.

Changes:

  • Strip Accept-Encoding in copyRequestHeaders to enable automatic gzip decompression on the proxy→upstream hop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/proxy/proxy.go Outdated
func copyRequestHeaders(dst, src http.Header) {
for key, values := range src {
if strings.EqualFold(key, "Authorization") || strings.EqualFold(key, "Host") {
if strings.EqualFold(key, "Authorization") || strings.EqualFold(key, "Host") || strings.EqualFold(key, "Accept-Encoding") {
Comment thread internal/proxy/proxy.go Outdated
func copyRequestHeaders(dst, src http.Header) {
for key, values := range src {
if strings.EqualFold(key, "Authorization") || strings.EqualFold(key, "Host") {
if strings.EqualFold(key, "Authorization") || strings.EqualFold(key, "Host") || strings.EqualFold(key, "Accept-Encoding") {
@JaredHatfield JaredHatfield merged commit ea75440 into main May 21, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in UnitVectorY Labs May 21, 2026
@JaredHatfield JaredHatfield deleted the fix/strip-accept-encoding-proxy branch May 21, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants