Caddy is serving precompressed gzip files without the content-encoding: gzip header. I am not sure if this is by design or not. If it is by design how would one add the content-encoding: gzip` header to the response?
curl request/response example:
curl -vL http://localhost/Build/Web.data.gz
* Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /Build/Web.data.gz HTTP/1.1
> Host: localhost
> User-Agent: curl/7.84.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Length: 15188528
< Content-Type: application/gzip
< Etag: "rqwkjb91jjk"
< Last-Modified: Thu, 02 Mar 2023 16:59:35 GMT
< Server: Caddy
< Date: Thu, 02 Mar 2023 17:37:58 GMT
<
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
* Failure writing output to destination
* Closing connection 0
The way precompressed works is by making a request for the non-gzipped version of the file, i.e. http://localhost/Build/Web.data, and Caddy will serve that using the compressed copy on disk.
When you make a request directly for the gzipped file, Caddy will serve it as-is, with Content-Type: application/gzip.
If you make a request for the non-compressed URL, then it implies that the client wants to read the contents uncompressed. If you request .gz then it implies you want to read it as compressed (e.g. for download). It’s semantically different.
Gotcha. Is there any way to get the content-encoding: gzip header to be written in this case? I am using a library that is specifically looking for the header and it fails without it.
Thank you for sharing your solution. Was this by any chance for Unity? I added the header directive but the .gz files are still being served without Content-Encoding: gzip. Here’s my Caddyfile: