Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure X-Sendfile sends correct Content-Length #10

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

kevinmcconnell
Copy link
Collaborator

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 golang/go@fdc21f3).

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.

In most cases, `http.ServeFile` will set this for us. However, it will
not set it if the response also has a `Content-Encoding`.

(golang/go@fdc21f3)

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`.
@kevinmcconnell kevinmcconnell merged commit c0fff3b into main Mar 18, 2024
1 check passed
@kevinmcconnell kevinmcconnell deleted the sendfile-header-bug branch March 18, 2024 13:46
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.

CSS files empty
1 participant