当我的代理出现内部错误时,返回 502 状态代码是否正确?
我编写了一个小型代理,我想知道当代理服务器本身出现内部错误时返回 502 Bad Gateway
错误是否正确。 RFC 似乎说只有在服务器另一端给出了不好的响应。
服务器在充当网关或代理时,从它在尝试满足请求时访问的上游服务器接收到无效响应。
我认为这意味着,如果上游服务器设置的 content-length
标头与响应正文长度不同,我们应该设置一个 502
错误,即当响应无效。
我是否误解了 RFC?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无效的 Content-Length 也可以像无效响应(502 错误)一样被处理。 503 仅应在条件是临时的时使用,即相同的请求可以在稍后的时间得到服务。
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.
通常的做法是使用 500 AFAIK。这在某种程度上是错误的,因为源服务器和代理之间没有区别。我还观察到服务器返回 504,但我认为这种行为是错误的。
The common practice is to use 500 AFAIK. This is in a way wrong, as there's no distinction between the origin server and the proxy. I've also observed servers returning 504, but I consider this behavior wrong.