服务器是否应该遵守从客户端发送的 HTTP Connection: close 标头? [英] Should a server adhere to the HTTP Connection: close header sent from a client?

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

问题描述

我有一个 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 Connection: close 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆