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 curl with the -v flag to inspect headers and body, and then pipe the output to gzip -t to test the integrity of the compressed data.
    curl -v "https://example.com/some/resource" -o response.gz
    gzip -t response.gz
    
    If gzip -t reports 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 -t specifically 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 -v is your friend. Look for the Content-Encoding header in the server’s response. If it says gzip or deflate, but the body, when saved and inspected (e.g., using file command on Linux/macOS), doesn’t appear to be compressed in that manner, you have a mismatch.
    curl -v "https://example.com/api/data" -o response.bin
    # Then inspect response.bin:
    file response.bin
    
    If file reports it as "ASCII text" or similar when Content-Encoding is gzip, it’s a mismatch.
  • Fix: If you control the server, fix its logic to either send the correct Content-Encoding header or send uncompressed data. If it’s a proxy, it might be incorrectly rewriting headers. Configure the proxy to pass through Content-Encoding headers 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-Encoding header 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-Encoding header sent by your client or proxy. If it includes br (Brotli) or zstd (Zstandard) but the server only supports gzip and deflate, and the server chooses to send gzip encoded data, but your client/proxy only knows how to handle br or zstd (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.
    curl -v --compressed "https://example.com/static/asset.js"
    # Or for custom headers:
    curl -v -H "Accept-Encoding: br, gzip" "https://example.com/resource"
    
    Check the Content-Encoding header in the response. If it’s something your client should be able to handle but fails, and you suspect your Accept-Encoding is too broad or unusual, try limiting it.
  • Fix: Modify the client or proxy to send a more compatible Accept-Encoding header, typically gzip, deflate or just gzip.
    # 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-Encoding and the raw response body at different points in the chain.
    # 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"
    
    Compare the Content-Encoding headers 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 with deflate but not gzip) 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 gzip encoding 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_flush directive can be set to auto or always.
    # 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.

Want structured learning?

Take the full Http course →