The HTTP decompression failed error means a component in your request chain (client or proxy) received a compressed response it couldn’t decompress, usually because the compression method advertised in the Content-Encoding header doesn’t match the actual encoding of the body, or the body is corrupted.
Here are the common culprits and how to fix them:
1. Corrupted Gzip Data:
- Diagnosis: Use
curlwith the-vflag to inspect headers and body, and then pipe the output togzip -tto test the integrity of the compressed data.
Ifcurl -v "https://example.com/some/resource" -o response.gz gzip -t response.gzgzip -treports an error like "unexpected end of file" or "invalid compressed data," the data is corrupted. - Fix: This usually indicates a network issue or a bug in the server’s compression logic. There’s no direct fix on the client/proxy side other than disabling compression or retrying. On the server, ensure the compression process is robust and doesn’t truncate data. If it’s a proxy, ensure it’s not interfering with or corrupting the stream.
- Why it works:
gzip -tspecifically checks for the integrity of the gzip stream according to the gzip format specification.
2. Mismatched Content-Encoding Header and Actual Content:
- Diagnosis: Again,
curl -vis your friend. Look for theContent-Encodingheader in the server’s response. If it saysgzipordeflate, but the body, when saved and inspected (e.g., usingfilecommand on Linux/macOS), doesn’t appear to be compressed in that manner, you have a mismatch.
Ifcurl -v "https://example.com/api/data" -o response.bin # Then inspect response.bin: file response.binfilereports it as "ASCII text" or similar whenContent-Encodingisgzip, it’s a mismatch. - Fix: If you control the server, fix its logic to either send the correct
Content-Encodingheader or send uncompressed data. If it’s a proxy, it might be incorrectly rewriting headers. Configure the proxy to pass throughContent-Encodingheaders or to correctly decompress/recompress if it’s intended to modify content. For a client, you might be able to disable decompression for this specific request or server. - Why it works: The client or proxy relies on the
Content-Encodingheader to know which decompression algorithm to apply. A mismatch leads to attempting to decompress non-compressed data or using the wrong algorithm.
3. Incorrect Accept-Encoding Header from Client/Proxy:
- Diagnosis: Examine the
Accept-Encodingheader sent by your client or proxy. If it includesbr(Brotli) orzstd(Zstandard) but the server only supportsgzipanddeflate, and the server chooses to sendgzipencoded data, but your client/proxy only knows how to handlebrorzstd(unlikely for standard clients, but possible with custom configurations), this could cause issues. More commonly, the client/proxy might advertise support for a less common encoding, and the server, for some reason, sends it, but the client’s decompression library fails.
Check thecurl -v --compressed "https://example.com/static/asset.js" # Or for custom headers: curl -v -H "Accept-Encoding: br, gzip" "https://example.com/resource"Content-Encodingheader in the response. If it’s something your client should be able to handle but fails, and you suspect yourAccept-Encodingis too broad or unusual, try limiting it. - Fix: Modify the client or proxy to send a more compatible
Accept-Encodingheader, typicallygzip, deflateor justgzip.# For curl, to force only gzip: curl -v -H "Accept-Encoding: gzip" "https://example.com/resource" - Why it works: This forces the server to respond with an encoding that the client is guaranteed to understand and can decompress.
4. Intermediate Proxy Modifying or Corrupting Compressed Data:
- Diagnosis: If you have multiple proxies in the chain (e.g., a load balancer, a WAF, and then your application server), one of them might be interfering. Test by bypassing proxies where possible. If you can’t bypass, inspect the
Content-Encodingand the raw response body at different points in the chain.
Compare the# Example: Test directly to origin server if possible curl -v "http://<origin_ip>:<origin_port>/resource" # Then test through the proxy curl -v "https://your.proxy.com/resource"Content-Encodingheaders and, if possible, attempt to decompress the response body at each stage. - Fix: Configure the problematic proxy to either pass through compressed data without modification or to correctly handle compression/decompression. Often, proxies that perform SSL termination or content inspection can inadvertently corrupt compressed streams if not configured properly. Ensure any relevant compression/decompression modules in the proxy are enabled and correctly configured, or disabled if they are not needed.
- Why it works: The proxy needs to be aware of and correctly handle compressed data, especially if it’s inspecting or modifying the payload.
5. Client-Side Decompression Library Issues or Bugs:
- Diagnosis: This is less common with standard libraries (like those in
curl, browsers, or common application frameworks) but can occur with custom implementations or older/buggy versions. If the error consistently happens for a specific type of compression (e.g., always withdeflatebut notgzip) and only on a particular client environment, suspect the library. - Fix: Update the client’s libraries to their latest stable versions. If using a custom decompression routine, thoroughly test it against known valid compressed data. As a workaround, configure the client to request only
gzipencoding if that is known to be reliable. - Why it works: Newer library versions often contain bug fixes that resolve issues with edge cases or specific data patterns encountered during decompression.
6. Server Not Properly Flushing Compression Buffers:
- Diagnosis: The server might be compressing data but not flushing its internal buffers correctly, leading to incomplete compressed streams being sent. This often manifests as "unexpected end of file" errors during decompression, similar to data corruption. You’d diagnose this by observing the response size and timing. If a large file is being streamed and the decompression fails mid-way, it’s a strong indicator.
- Fix: On the server-side application or web server configuration (e.g., Nginx, Apache), ensure that compression modules are configured to flush buffers appropriately, especially for streaming responses. For example, Nginx’s
gzip_flushdirective can be set toautooralways.# Example Nginx config: gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; gzip_min_length 1024; gzip_comp_level 6; gzip_flush auto; # or always - Why it works: Properly flushing buffers ensures that the complete compressed data for a given chunk is sent over the network, allowing the decompressor to process it without encountering an premature end of the stream.
The next error you’ll likely hit after fixing these is a 502 Bad Gateway if your proxy is still unable to communicate properly with the origin, or a 504 Gateway Timeout if the upstream server is now responding but taking too long due to other underlying performance issues.