basecamp / thruster

MIT License
672 stars 16 forks source link

Ensure X-Sendfile sends correct `Content-Length` #10

Closed kevinmcconnell closed 3 months ago

kevinmcconnell commented 3 months ago

In most cases, http.ServeFile will set this for us. However, it will not set it if the response also has a Content-Encoding (see https://github.com/golang/go/commit/fdc21f3eafe94490e55e0bf018490b3aa9ba2383).

If we don't set (or at least clear) the header in that case, we'll pass through the Content-Length of the upstream's response, which can lead to us serving an incomplete response.

In particular, this happens when Rails is serving a gzipped asset via X-Sendfile, which it does using Content-Encoding: gzip and Content-Length: 0.

Fixes #8.