Should a server adhere to the HTTP Connection: close header sent from a client?

谁都会走 提交于 2019-12-21 09:23:31

问题


I have a HTTP client that sets the Connection header to the following value when I make a request:

   Connection: close

However when the server sends a response, it is setting the header to Keep-Alive:

   Connection: Keep-Alive

This seems intuitively wrong to me, and I am wondering how the client should handle such a response from the server? Also why would a server respond with Keep-Alive, when the client has asked for the connection to be closed, is this valid?

According to the HTTP RFC:

"HTTP/1.1 defines the "close" connection option for the sender to signal that the connection will be closed after completion of the response. For example,

   Connection: close

in either the request or the response header fields indicates that the connection SHOULD NOT be considered `persistent' (section 8.1) after the current request/response is complete."


回答1:


That's fine. You are telling the server you don't support persistent connections and it's telling you it does. Either party is completely valid in closing the connection - it's more of a message about what both supports rather then a YOU MUST CLOSE THIS CONNECTION command.




回答2:


The client says I will close the connection when the current request/response is finished,or in other words , said you don't support persisten connections. That is, it doesn't tell the server to close the connection. The server replies that it supports persistent connections(keep-alive).

As you've told the server that you don't support persistent connection, you should close the connection when you've read the response.



来源:https://stackoverflow.com/questions/3424796/should-a-server-adhere-to-the-http-connection-close-header-sent-from-a-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!