http - 在 HTTP 502 中,无效响应是什么意思?

标签 http httpresponse rfc standards-compliance

我正在尝试测试服务器以查看其行为是否符合以下定义,为此,我需要构建无效响应并将其从上游服务器发送到网关服务器。 HTTP 规范说明了以下关于状态代码 502 - Bad Gateway 的内容。

The 502 (Bad Gateway) status code indicates that the server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request.

但究竟什么构成无效响应?非标准响应代码(例如,一些随机数,如 6789)是否算作无效响应?还是带有无效 HTTP 版本的响应?

遇到这个:502 HTTP Status Code ,它表示不完整的 header 和响应主体可能会导致 502 错误。服务器如何确定 header 或正文是否不完整?更重要的是,是否可以通过编程方式创建这样的响应(我使用的是 Java)?

最佳答案

我设法在 HTTP 规范(RFC7230 第 3.3.3 节)中找到以下内容。

If a message is received without Transfer-Encoding and with either multiple Content-Length header fields having differing field-values or a single Content-Length header field having an invalid value, then the message framing is invalid and the recipient MUST treat it as an unrecoverable error. If this is a request message, the server MUST respond with a 400 (Bad Request) status code and then close the connection. If this is a response message received by a proxy, the proxy MUST close the connection to the server, discard the received response, and send a 502 (Bad Gateway) response to the client. If this is a response message received by a user agent, the user agent MUST close the connection to the server and discard the received response.

除此之外,我还注意到当上游服务器关闭时,Nginx 在充当反向代理/负载平衡器时返回 502。

关于http - 在 HTTP 502 中,无效响应是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35660464/

相关文章:

http - F# HTTP Post,读取状态码响应

java - 可用的不同 HttpClient 之间有什么区别?

java - RFC3986 - 哪些 pchars 需要进行百分比编码?

ssl - OpenSSL 对客户端证书 URL 的支持

php - 如何使用 PSR-7 响应?

json - 在 JsonSchema 中,格式值应设置为 "full-date"或 "date"?

c - 重复使用客户端TCP套接字进行多个HTTP连接

web-services - 在自定义 Internet 媒体类型(MIME 类型)中使用加号

c# - 强制下载 PDF 时使用 Response.End

java - org.apache.http.ProtocolException : Target host is not specified