@marcel91200 / caddy Mirror · read-only / commits / b4626154
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 21:00 UTC

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>

WeidiDeng committed Sep 11, 2025 at 12:48 UTC b462615439bf354dd1cb6780fb564b6a6c4a352c
1 file changed +5 -5
modules/caddyhttp/fileserver/staticfiles.go
+5 -5
@@ -458,12 +458,12 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
458 defer file.Close()
459 respHeader.Set("Content-Encoding", ae)
460
461 - // stdlib won't set Content-Length if Content-Encoding is set.
462 - // set Range header if it's not present will force Content-Length to be set
461 + // stdlib won't set Content-Length for non-range requests if Content-Encoding is set.
462 + // see: https://github.com/caddyserver/caddy/issues/7040
463 + // Setting the Range header manually will result in 206 Partial Content.
464 + // see: https://github.com/caddyserver/caddy/issues/7250
465 if r.Header.Get("Range") == "" {
464 - r.Header.Set("Range", "bytes=0-")
465 - // remove this header, because it is not part of the request
466 - defer r.Header.Del("Range")
466 + respHeader.Set("Content-Length", strconv.FormatInt(compressedInfo.Size(), 10))
467 }
468
469 // try to get the etag from pre computed files if an etag suffix list was provided