@marcel91200 / caddy Mirror · read-only / commits / 67debd0e
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, 22:15 UTC

fileserver: set Range header for precompressed static files to force Content Length header to appear (#7042)

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>

WeidiDeng committed Aug 22, 2025 at 22:23 UTC 67debd0e11c3c880bb6fc7a92325989576b0a7fa
1 file changed +8 -1
modules/caddyhttp/fileserver/staticfiles.go
+8 -1
@@ -457,7 +457,14 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
457 }
458 defer file.Close()
459 respHeader.Set("Content-Encoding", ae)
460 - respHeader.Del("Accept-Ranges")
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
463 + 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")
467 + }
468
469 // try to get the etag from pre computed files if an etag suffix list was provided
470 if etag == "" && fsrv.EtagFileExtensions != nil {