Skip to content

vhost: stop the HTTP reverse proxy silently inflating gzip responses - #1

Merged
lucaa6i merged 1 commit into
devfrom
fix/disable-transparent-gzip
Aug 24, 2026
Merged

lucaa6i merged 1 commit into
devfrom
fix/disable-transparent-gzip

Conversation

@JulienGrv

Copy link
Copy Markdown
Member

One line in pkg/util/vhost/http.go: DisableCompression: true on the reverse proxy's http.Transport.

What happens today

http.Transport defaults DisableCompression to false. When a caller sends no Accept-Encoding, the Transport adds Accept-Encoding: gzip on its own behalf, then transparently decodes the response and strips Content-Encoding and Content-Length. That is the right convenience for application code using http.Client. In a reverse proxy it rewrites the representation the upstream chose.

Measured against a homee cube serving a pre-gzipped file through frps:

client Accept-Encoding bytes content-encoding
gzip 262,107 gzip
identity 262,107 gzip
deflate 262,107 gzip
foobar 262,107 gzip
absent 1,239,673 (none)

The upstream sent 262,107 bytes with Content-Encoding: gzip in every one of those cases — verified by querying the cube's own listener with no proxy in the path, byte-identical with and without the header. Only the absent-header case is rewritten, and the response also loses Content-Length and becomes chunked, which is the tell for on-the-fly inflation.

foobar is the case that rules out an nginx gunzip further down the chain: the client plainly does not accept gzip there, and the body is still relayed compressed. Only the Go Transport behaves that way.

RFC 9110 is explicit that an absent Accept-Encoding means any content coding is acceptable, so relaying the upstream's gzip is correct and inflating it is not.

Trade-off worth stating

This also stops the Transport requesting gzip on its own behalf. For an upstream that honours Accept-Encoding, a client sending no header will now get an uncompressed body where the tunnel previously carried a compressed one. Correct relaying seems clearly worth that, and a client that wants compression should ask for it — but it is a real change for anyone relying on the current behaviour as an implicit optimisation.

Not affected: transport.useCompression / --uc. That is snappy over the frpc↔frps work connection (libio.WithCompressionFromPool), a layer below HTTP, and orthogonal to this.

Verifying

curl -s -D- -o /dev/null -H 'Accept-Encoding;' https://<subdomain>/<a-gzipped-file>
  • before: no content-encoding, no content-length, inflated body
  • after: content-encoding: gzip, content-length present, bytes as the upstream sent them

Sending -H 'Accept-Encoding: gzip' returns the compressed body either way, which is why this hides from most testing.

This looks like an upstream bug in fatedier/frp rather than anything specific to this fork — worth sending on.

http.Transport defaults DisableCompression to false, so when a caller sends
no Accept-Encoding the Transport adds "Accept-Encoding: gzip" of its own
accord, then transparently decodes the response and drops Content-Encoding
and Content-Length. That is a convenience for application code using
http.Client; in a reverse proxy it rewrites the representation the upstream
chose.

Measured serving a pre-gzipped file: a client sending no Accept-Encoding
received 1,239,673 bytes of plain text, chunked and unlabelled, where the
upstream had sent 262,107 bytes with Content-Encoding: gzip. A client that did
send the header got the gzip untouched, which is why this hides from most
testing.

RFC 9110 is explicit that an absent Accept-Encoding means any content
coding is acceptable, so relaying the upstream's gzip is correct and
inflating it is not.

Note this also stops the Transport requesting gzip on its own behalf, so an
upstream that honours Accept-Encoding may now send an uncompressed body
where it previously sent a compressed one over the tunnel. Correct
relaying is worth that; a client wanting compression should ask for it.
@JulienGrv
JulienGrv force-pushed the fix/disable-transparent-gzip branch from 2da7c58 to cd4a8f5 Compare August 24, 2026 09:36
@lucaa6i
lucaa6i merged commit 12805ac into homee:dev Aug 24, 2026
1 check failed
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.

2 participants