Search code examples
httphttp-headersgziphttp-error

Can a response to an http request error be gziped?


When trying to execute an http request that causes a 400 Bad Request error, an nginx server returns the "400 Bad Request", a Content-Encoding: gzip, and the response in a non-encoded format.

So because of the Content-Encoding: gzip my code wraps the response with a GZIPInputStream which throws an error.

My question is: is gzip a valid encoding when the status code is not "200 OK"? if not, I can simply check for the status code and not try to gzip if anything other than 200 was returned.

Are there rules/guidelines about this? Is this documented anywhere?

TIA


Solution

  • Yes, it is a valid encoding. Content-Encoding (and Transfer-Encoding) are orthogonal to status codes.