HTTP header Get 响应没有内容长度给出 502 bad gateway
要创建彗星连接(挂起获取),我没有在 HTTP 标头中指定内容长度。这在我的系统上有效,但会从研究所 LAN 的另一台机器请求,它为请求提供 502 Bad Gateway。
如果我提到内容长度,我会得到响应,但连接会关闭,这是我不想要的。有什么替代方案?
To create a comet connection (hanging get) i am not specifying the content-length in HTTP Header. This works on my system but will requested from another machine of institute LAN, it gives 502 Bad Gateway for the request.
If i mention content-length, i get the response but the connection gets closed, which i dont want. What can be the alternatives to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
遵循 HTTP/1.1 规范来保持连接。在回复中返回
HTTP/1.1
。如果查询是 HTTP/1.1,则默认保持连接打开。如果查询不是,则默认关闭它。如果您收到Connection: close
标头,请在发送响应后关闭连接。如果您收到Connection: keep-alive
标头,请保持连接打开,即使这不是协议默认值。如果您不想遵循
HTTP/1.1
,那么无论如何您都可以获得连接持久性。如果您通过上述规则成功建立持久性,则始终包含Connection: Keep-Alive
标头。如果您无法支持持久连接(即使客户端请求了一个连接),请发送Connection: Close
标头。基本上,遵循 HTTP 规范。如果您知道内容长度,则应始终发送
Content-Length
标头。如果客户端可以支持持久连接,请使用持久协商规则来建立持久连接。Follow the HTTP/1.1 specification for connection persistence. Return
HTTP/1.1
in the reply. If the query was HTTP/1.1, default to keeping the connection open. If the query wasn't, default to closing it. If you get aConnection: close
header, close the connection after sending the response. If you get aConnection: keep-alive
header, keep the connection open even if that wasn't the protocol default.If you don't want to follow
HTTP/1.1
, you can probably get connection persistence anyway. Just always include aConnection: Keep-Alive
header if you successfully establish persistence through the rules above. Send aConnection: Close
header if you cannot support a persistent connection even though the client requested one.Basically, follow the HTTP specification. If you know the content length, you should always send a
Content-Length
header. Use the persistence negotiation rules to establish a persistent connection if the client can support one.