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?
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 a Connection: close
header, close the connection after sending the response. If you get a Connection: 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 a Connection: Keep-Alive
header if you successfully establish persistence through the rules above. Send a Connection: 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.
精彩评论