Server & Hosting Performance

Cloudflare changes how byte-range downloads handle compression

A November 24 cache update changes both what the edge serves and what some origin servers see.

A cached file branches into a highlighted byte segment and a complete file beside two browser windows.

Cloudflare changed how its CDN answers a request for part of a compressed file when the client has not explicitly accepted the stored encoding. A downloader asking for the next chunk can now receive a complete file with HTTP status 200. Software that resumes transfers needs to inspect that status before appending anything to disk.

Why the byte positions matter

A range request identifies a portion of the representation the server will send. For example, Range: bytes=0-1023 asks for the first 1,024 bytes, counting both endpoints. A gzip version of a public dataset and its uncompressed version contain the same information after decoding. Their byte positions, lengths and contents on the wire differ. An offset saved from one version cannot tell a downloader where to resume in the other.

In its November 24 description of the range-request change, Cloudflare said its previous behavior could return a partial response with bytes that disagreed with the advertised range when the client did not accept the cached encoding. Imagine a transfer tool that simply seeks to the position in its progress file and writes the new bytes. The HTTP exchange can finish successfully while the file assembled on disk contains portions of two different representations. A checksum of the complete download can reveal that problem much later.

When the edge sends the whole file

For a cached gzip file, the client must explicitly include gzip in Accept-Encoding with a weight above zero to qualify for that encoded range. The equivalent rule applies to a cached Brotli file, with the additional requirement of HTTPS. A client that sends gzip;q=0 has specifically refused gzip. In those cases where the cached range cannot be served under the new rule, the edge negotiates a complete response and returns 200 OK. The complete body can have a different encoding from the cached object.

Cloudflare also documents a separate rule for cached files encoded with Zstandard or deflate. It returns the complete file for those encodings. Avoid building a test that expects every accepted encoding to produce a partial response. For a public file that people download over a metered connection, record how many bytes traveled on each path. A request count or success rate alone conceals the cost of restarting a large transfer. The site's guide to CDN and edge caching explains how to distinguish an edge hit from a trip to the origin.

What reaches an origin on an HTTPS GET

When the request bypasses the cache or is ineligible for caching, Cloudflare forwards the range to the origin. For an HTTPS GET on that path it now forwards the client's own encoding preference, replacing the previous default of gzip and Brotli. The origin can then select an encoding the client accepts. Cloudflare distinguishes this path from range requests served from cache or fetched by its Origin Range Requests feature. On those paths its own encoding preference still applies upstream.

In some configurations the origin can receive an explicitly empty Accept-Encoding value. Cloudflare gives the example of a request that listed only dictionary encodings stripped on the way upstream. The origin should serve an unencoded representation when it receives that empty value. If only one route starts returning 406, inspect the actual upstream header, the request method and the cache rule before changing compression for the whole site.

Test the bytes as well as the status

Use a small, public, versioned fixture on an edge route you control. Choose one long enough to contain the range you will request. Download the full representation and a slice using the same URL, encoding preference and file version. Keep automatic content decoding switched off in your command-line client. The following example writes a full body and a separate sample to the current directory.

shell
curl -sS -D full.headers -H 'Accept-Encoding: gzip' "$URL" -o full.bin
curl -sS -D part.headers -H 'Accept-Encoding: gzip' \
  -H 'Range: bytes=0-1023' "$URL" -o part.bin

Check both statuses and both content encodings. For a single-range 206, read the start and end offsets in Content-Range. If both transfers used the same representation and the advertised span is zero through 1,023, compare the sample with exactly those first 1,024 bytes of the saved full body. For a 200, inspect the response as a separate, complete transfer. Repeat with a client that accepts only the identity encoding and compare observations for cached and bypassed requests separately.

Finally, exercise the downloader itself. Interrupt a transfer, resume it against an unchanged public fixture and verify the completed file against a trusted digest. Repeat after a controlled change to the fixture's version. A full response must start a fresh output file. A partial response can extend the saved file only when its representation and starting offset match the saved state. Those two checks test the behavior a person actually depends on when they click Resume.

Related guides