Fix a compressed response Chrome can't unpack

ERR_CONTENT_DECODING_FAILED means your server labeled a response as compressed, with a header such as Content-Encoding: gzip, and Chrome couldn't decompress the body that followed. The label and the bytes disagree: the body was never compressed, something wrote text in front of the compressed data, or the label names a different format from the one used.

Why the body doesn't match its label

  • The body was never compressed

    Code or config that sets Content-Encoding by hand, or a proxy that decompresses a response and passes the header along unchanged, leaves plain HTML under a gzip label. Chrome tries to decompress it and fails.

  • Text sits in front of the compressed data

    A warning, notice or stray output written before compression starts ends up ahead of the compressed stream. The body no longer starts the way gzip requires, so decoding fails at the first byte.

  • The label names the wrong format

    A Brotli body labeled gzip, or a gzip body labeled br, fails too. Chrome decodes gzip, deflate, Brotli and Zstandard, and it picks the decoder from the label alone.

  • An unknown label passes through

    A label Chrome doesn't recognize doesn't cause this error. Chrome skips decoding and shows whatever arrived, which looks like garbage if the body was compressed.

RFC 9110 says Content-Encoding lists the codings a recipient has to undo to get the content back. Chromium's filter_source_stream.cc lists the codings Chrome decodes and passes unknown ones through untouched, and net_error_list.h describes this error as a failure to decode the response body.

Fetch the raw response and test it

# See which format the server picks when asked the way Chrome asks over HTTPS
curl -sS -H 'Accept-Encoding: gzip, deflate, br, zstd' -o /dev/null -D - https://yoursite.com/ \
  | grep -i '^content-encoding:'

# Ask for the formats this curl supports and let it decompress the reply
curl -sS --compressed -o /dev/null -D - https://yoursite.com/

# Ask for gzip only and save the body without decompressing it
curl -sS -H 'Accept-Encoding: gzip' -o page.gz -D - https://yoursite.com/

# Test the saved body and show its first bytes
gzip -t page.gz
head -c 32 page.gz | xxd

Read the results

  • The first command prints the format the server claims for Chrome, such as content-encoding: br, or nothing for an uncompressed response. If the second command prints only headers, curl decompressed the body without trouble. An error such as Error while processing content unencoding means curl hit the same mismatch Chrome did, and curl exits with code 61, which its manual calls an unrecognized transfer encoding. The second command asks only for formats your curl can decode, so if its content-encoding line differs from the first command's, it never tested the body Chrome gets.

  • Run the gzip test only when the third command's headers say content-encoding: gzip. gzip -t prints nothing for a valid body and an error otherwise: not in gzip format when the body was never gzip, or unexpected end of file when it was cut short. A gzip stream always opens with the bytes 1f 8b, as RFC 1952 fixes. If xxd shows readable text there instead, such as an HTML doctype or a warning message, the body was never compressed or something wrote in front of it.

How to fix a content decoding error

  1. Find where the label appearsFetch the page from your app server directly, then through each proxy or CDN in front of it. The first layer where the label and the body disagree is the one to fix.
  2. Stop setting the label by handRemove code or config that adds Content-Encoding on its own, and let the server's compression module or the CDN set it together with the compressed body.
  3. Keep stray output out of the bodyTurn off on-screen warnings and notices in production and remove anything that prints before the response starts, so nothing lands in front of the compressed data.
  4. Fix the label when a layer decompressesA proxy or CDN that decompresses a response to change it has to remove Content-Encoding, or compress the result again under the right label. Then run the curl commands again.

Frequently asked questions

Why does the page load with curl but not in Chrome?

Plain curl doesn't ask for compression or decompress anything, so it never notices a mismatch. --compressed asks only for the formats your curl supports, as curl's manual says, and curl -V lists brotli and zstd under Features when it has them. Chrome over HTTPS asks for gzip, deflate, br and zstd, as Chromium's http_request_headers.cc sets. Send Chrome's list with -H 'Accept-Encoding: gzip, deflate, br, zstd' to see the format Chrome gets.

Can a CDN cause this error?

Yes, when it changes a response without keeping the label accurate, for example by decompressing the HTML to rewrite it and passing the original Content-Encoding header along. Compare the headers your server sends with the ones the CDN sends for the same URL to find out.

Why is only one file affected?

The label is set response by response, and compression rules often apply by file type or route. If only a script, a stylesheet or one page fails, test that URL; its handler, or a rule for its type, is where the label goes wrong.