I've written a small proxy, and I'm wondering if it's correct for me to return a 502 Bad Gateway
error when the proxy server itself has an internal error. The RFC seem to say that this is something you only do if the server on the other end gives a bad response.
The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
I take this to mean that if for example the upstream server is setting a content-length
header that is different from the response body length, we should set a 502
error i.e. when the response is invalid.
Am I misinterpreting the RFC?
An invalid Content-Length could just as well be handled as an invalid response (502 error). 503 should only be used when the condition is temporary, i.e., the same request can be served at a later time.