mirror of
https://github.com/caddyserver/caddy.git
synced 2025-09-29 15:31:06 -04:00
fileserver: set Content-Length for precompressed files (#7251)
* set Content-Length for precompressed files * Update modules/caddyhttp/fileserver/staticfiles.go Co-authored-by: Matt Holt <mholt@users.noreply.github.com> --------- Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
parent
012b4b3d40
commit
b462615439
@ -458,12 +458,12 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
|||||||
defer file.Close()
|
defer file.Close()
|
||||||
respHeader.Set("Content-Encoding", ae)
|
respHeader.Set("Content-Encoding", ae)
|
||||||
|
|
||||||
// stdlib won't set Content-Length if Content-Encoding is set.
|
// stdlib won't set Content-Length for non-range requests if Content-Encoding is set.
|
||||||
// set Range header if it's not present will force Content-Length to be set
|
// see: https://github.com/caddyserver/caddy/issues/7040
|
||||||
|
// Setting the Range header manually will result in 206 Partial Content.
|
||||||
|
// see: https://github.com/caddyserver/caddy/issues/7250
|
||||||
if r.Header.Get("Range") == "" {
|
if r.Header.Get("Range") == "" {
|
||||||
r.Header.Set("Range", "bytes=0-")
|
respHeader.Set("Content-Length", strconv.FormatInt(compressedInfo.Size(), 10))
|
||||||
// remove this header, because it is not part of the request
|
|
||||||
defer r.Header.Del("Range")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to get the etag from pre computed files if an etag suffix list was provided
|
// try to get the etag from pre computed files if an etag suffix list was provided
|
||||||
|
Loading…
x
Reference in New Issue
Block a user