When wrapping a handler that supports HTTP Range-Requests (e.g. http.FileServer), gziphandler relays them as-is, thus violating the HTTP standard and breaking clients.
That means, currently, gziphandler compresses ranges returned by the wrapped handler instead of returning ranges of the compressed output (of the complete wrapped content).
The HTTP standard basically says that Content-Length is the size of the Content-Encoding output and that range requests specify ranges into the Content-Encoding encoded output, as well.
Expected behavior: Either (a) gziphandler filters out the Accept-Ranges: bytes headers in wrapped handler responses (and any Range: headers in passed requests), or, (b) it handles Range-Requests on its own and doesn't pass them down to the wrapped handler.
Note that implementing (b) would be kind of complicated, e.g. a range that is smaller than the configured minSize would have to trigger a compression up to the range end.
When wrapping a handler that supports HTTP Range-Requests (e.g.
http.FileServer
), gziphandler relays them as-is, thus violating the HTTP standard and breaking clients.That means, currently, gziphandler compresses ranges returned by the wrapped handler instead of returning ranges of the compressed output (of the complete wrapped content).
The HTTP standard basically says that
Content-Length
is the size of theContent-Encoding
output and that range requests specify ranges into theContent-Encoding
encoded output, as well.Expected behavior: Either (a) gziphandler filters out the
Accept-Ranges: bytes
headers in wrapped handler responses (and anyRange:
headers in passed requests), or, (b) it handles Range-Requests on its own and doesn't pass them down to the wrapped handler.Note that implementing (b) would be kind of complicated, e.g. a range that is smaller than the configured minSize would have to trigger a compression up to the range end.
How to reproduce:
Create a handler like this:
Request a full compressed page:
Note how the Content-Length is the size of the compressed content, as expected.
Getting a range:
Note the following issues:
And the range isn't a prefix of the previous result:
Another range request:
Similar issues as before and the range isn't gzip-compressed.