Your bulk export downloader requests 100 bytes at a time. On the next attempt, it asks for the same interval and receives the whole file. If it appends that body, the retry corrupts the download. Even two responses that are both 100 bytes long are not interchangeable if their bytes came from different encodings.
Cloudflare’s November 24, 2026 update is a reason to make three checks explicit: Is this a partial response? Which encoding do its offsets refer to? Is it still the same file version? For large dataset or model exports, establish those guarantees before tuning transfer compression.
01 · The offsets are measured before decompression
Range: bytes=100-199 includes both endpoints. A successful single range here is 100 bytes. Under RFC 9110 §14.1.2, those offsets apply to the selected representation. With Content-Encoding: gzip, offset 100 is an offset into the gzip stream, not into the decoded source.
To make the difference visible, I repeated one ASCII line 4,096 times, compressed the resulting bytes at gzip level 6, and sliced both forms at the same offsets. Three runs on Python 3.12.14 with zlib 1.3.2 agreed. This was a local byte replay, not a Cloudflare request.
Local replay: gzip is 293 B and identity is 94,208 B. The 100 B slices have SHA-256 prefixes b6a19b009056 and 950b7031991c, respectively.
| Selected representation | Example range notation | Slice size | SHA-256 prefix |
|---|---|---|---|
| gzip | bytes 100-199/293 | 100 B | b6a19b009056 |
| Unencoded | bytes 100-199/94208 | 100 B | 950b7031991c |
The 293 B result comes from an unusually repetitive synthetic input, not a typical compression ratio. The useful observation is that the lengths matched and the bytes didn't. You can reconstruct a gzip stream by joining the original slices of that same stream in order. You cannot mix them with slices of the unencoded file.
02 · When Cloudflare sends 200 instead of 206
According to Cloudflare’s range request documentation, a cached gzip file can be served as a range when the client explicitly accepts gzip. gzip;q=0, a bare *, and no header do not meet that requirement. Brotli also requires HTTPS, and a Workers subrequest without the Brotli compatibility flag will not receive a Brotli range.
If the encoding condition fails, Cloudflare processes the request as a full 200 OK using ordinary content negotiation. Cached zstd and deflate representations also take the full-response path. An unencoded cache entry is a counterexample: a client asking for identity can still receive a valid 206 if the file supports ranges. Hard-coding “identity means 200” would discard a valid response.
An uncached HTTPS GET that bypasses or is ineligible for cache follows a different path. Cloudflare changed it to forward the client's range and encoding headers to the origin, so the origin's response matters. The separately generated Origin Range Requests are not that pass-through path. Do not infer the origin’s behavior from a single cached response.
03 · Check the response before appending
If the downloader must address unencoded bytes, send Accept-Encoding: identity in staging and confirm that the endpoint actually serves unencoded ranges. If the product stores the gzip representation itself, it can instead retain a consistent encoding and strong ETag, then decompress only after assembling that same stream. An origin that changes its encoding or recompresses the file is a reason not to reuse old slices, even if the URL is unchanged.
206: For a single range, check the start, end, and total in
Content-Range, the byte count, and the saved encoding and version. With a trustworthy strong ETag, use If-Range. Do not append if you cannot verify the match.200: This is the complete representation, not the requested slice. Restart by replacing the old download, or stop; never append it.
416: Check the current size and resume offset. The offset may be past the end, or the file may have changed. Do not loop on the same request.
04 · Compare three sets of headers on your own endpoint
Replace the URL below with an authorized staging file. The command intentionally omits --compressed so the response bytes are not automatically decoded. Compare the headers and saved lengths for three requests to the same file. This is a reader verification procedure, not an edge test I ran for this article.
url='https://staging.example.com/export.txt' for ae in gzip identity 'gzip;q=0, identity'; do case "$ae" in gzip) name=gzip;; identity) name=identity;; *) name=gzip-zero;; esac curl -sS -H 'Range: bytes=100-199' -H "Accept-Encoding: $ae" \ -D "$name.headers" -o "$name.bin" "$url" printf '%s: ' "$ae"; wc -c < "$name.bin" grep -Ei '^(HTTP/|content-range:|content-encoding:|etag:|cf-cache-status:)' \ "$name.headers" done 공통 재현 코드 / Shared replay
import gzip import hashlib import sys plain = b"NDJSON export row 0001\n" * 4096 encoded = gzip.compress(plain, compresslevel=6, mtime=0) start, end = 100, 199 wire = encoded[start:end + 1] decoded = plain[start:end + 1] print(sys.version.split()[0], len(plain), len(encoded)) for label, part, total in [("gzip", wire, len(encoded)), ("identity", decoded, len(plain))]: print(label, f"bytes {start}-{end}/{total}", len(part), hashlib.sha256(part).hexdigest()[:12]) assert len(wire) == len(decoded) == 100 and wire != decoded assert gzip.decompress(encoded) == plain assert encoded[:100] + wire + encoded[200:] == encoded 관측 / Observed: Python 3.12.14 · zlib 1.3.2 · 3 identical runs. Unencoded total 94,208 B; gzip total 293 B. The two 100 B slices had different SHA-256 prefixes, and the full gzip stream decoded exactly to the input. A different zlib version can generate different gzip bytes.

