本文介绍了服务器是否应该遵守从客户端发送的HTTP连接:关闭标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTTP客户端,当我发出请求时将Connection头设置为以下值:

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

   Connection: close

但是,当服务器发送响应时,它将标题设置为Keep-Alive:

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

   Connection: Keep-Alive

这看起来直觉上是错误的,我想知道客户端应该如何处理这样的响应从服务器?为什么服务器响应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?

根据HTTP RFC:

According to the HTTP RFC:

HTTP / 1.1定义了发送方的关闭连接选项,表示在响应完成后连接将被关闭。例如,

"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

在请求或响应头字段中指示在当前请求/响应完成后连接不应被视为持久(第8.1节)。

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."

推荐答案

没关系。你告诉服务器你不支持持久连接,它告诉你它。任何一方在关闭连接时是完全有效的 - 它更多是关于两者都支持的消息,而不是一个你必须关闭此连接命令。

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.

这篇关于服务器是否应该遵守从客户端发送的HTTP连接:关闭标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 11:19