Precompressed file setting response headers

1. The problem I’m having:

I am pre-compressing files with gzip in order to avoid Caddy having to compress the files on-the-fly. Caddy is loaded with “precompressed gzip” and this usually works great, but some files have issues. For example, favicon.ico will not appear in the icon tab, but it is clearly received by the browser.
I did some testing with not pre-compressing files and instead allow Caddy to compress on-the-fly with “encode gzip”.
What I noticed is when Caddy compresses them on the fly the previously broken favicon works. Checking the responses in Chrome dev tools shows an interesting difference between the pre-compressed and on-fly-compression.
It seems responses using “precompressed gzip” respond with a partial status code with Content-Length and Content-Range set, but “encode gzip” does not.
Below I have an image comparing the two responses for the favicon.ico, but all requests do this.
I suspect favicon needs the response to be code 200, and I am now worried more issues will start to appear if I continue to use precompression.
So, why is the Content-Length and Content-Range set for only precompressed files? The requests are exactly the same for both responses.

2. Error messages and/or full log output:

No Log

3. Caddy version:

2.10.2

4. How I installed and ran Caddy:

Docker compose

a. System environment:

Docker

b. Command:

N/A

c. Service/unit/compose file:

services:
  caddy-quant:
    container_name: quantcaddy
    image: caddy:2.10.2
    restart: unless-stopped
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - ./caddy-config:/config
      - ./caddy-data:/data
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./static:/usr/share/caddy/static

My complete Caddy config:

localhost:9000 {
    root * /usr/share/caddy
    file_server {
        precompressed gzip
    }

    #encode gzip

    @notStatic {
        not path /static/*
    }

    reverse_proxy @notStatic host.docker.internal:8000
}

5. Links to relevant resources:

None

1 Like

I think this bug is already fixed in 2.11.0-beta.1 if you can give it a shot. Unfortunately the Docker image isn’t released yet (should be in the coming days) but you can build from source with the builder image in the meantime if you’re in a rush Build from source — Caddy Documentation

1 Like

So, why is the Content-Length and Content-Range set for only precompressed files? The requests are exactly the same for both responses.

When a file is precompressed, you know the length, so Caddy sends the length header. It also allows a browser to download only part of a file, since the length is known

When a file is compressed on the fly, the length is not known, so there is no length header

The only bug here is that caddy sends a 206, even when the client does not requests a byte range

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.