Repository navigation
vhost: stop the HTTP reverse proxy silently inflating gzip responses - #1
Merged
Merged
Conversation
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
force-pushed
the
fix/disable-transparent-gzip
branch
from
August 24, 2026 09:36
2da7c58 to
cd4a8f5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One line in
pkg/util/vhost/http.go:DisableCompression: trueon the reverse proxy'shttp.Transport.What happens today
http.TransportdefaultsDisableCompressiontofalse. When a caller sends noAccept-Encoding, the Transport addsAccept-Encoding: gzipon its own behalf, then transparently decodes the response and stripsContent-EncodingandContent-Length. That is the right convenience for application code usinghttp.Client. In a reverse proxy it rewrites the representation the upstream chose.Measured against a homee cube serving a pre-gzipped file through
frps:Accept-Encodingcontent-encodinggzipidentitydeflatefoobarThe upstream sent 262,107 bytes with
Content-Encoding: gzipin 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 losesContent-Lengthand becomes chunked, which is the tell for on-the-fly inflation.foobaris the case that rules out an nginxgunzipfurther 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-Encodingmeans 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
content-encoding, nocontent-length, inflated bodycontent-encoding: gzip,content-lengthpresent, bytes as the upstream sent themSending
-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/frprather than anything specific to this fork — worth sending on.