net/http: FileServer: Content-Length is not set when Content-Encoding was set
#66,735 opened on Apr 9, 2024
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Go version
go version go1.22.2 darwin/arm64
Output of go env in your module/workspace:
N/A
What did you do?
I am trying to set Content-Encoding for .br brotli compressed files with http.FileServer.
This code then skips setting Content-Length because Content-Encoding is set: https://github.com/golang/go/blob/9f13665088012298146c573bc2a7255b1caf2750/src/net/http/fs.go#L377
This causes my httptest to fail with an empty Content-Length, as well as other cases where I call ServeHTTP without using the full http client: https://go.dev/play/p/2UvgBSH8FWx
When using http.Get it works correctly, so the client must be filling in the Content-Length: https://go.dev/play/p/xp08V07UrtQ
What did you see happen?
The content-length header is not set when the content-encoding header is set.
What did you expect to see?
I expect the content-length header to be set even if the content-encoding header is set.