在什么情况下关闭HTTP连接必要? [英] In What conditions are closing a HTTP connection necessary?

查看:186
本文介绍了在什么情况下关闭HTTP连接必要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么情况下需要关闭HTTP连接?

In What conditions are closing a HTTP connection necessary?

推荐答案

HTTP不是要连接的协议类型;它是他们所谓的无状态,意味着每个请求是与每个其他请求分开。这就是为什么我们有像会话cookie的东西;人们不得不以允许在请求之间传递信息的方式进行攻击。

HTTP isn't the type of protocol to have "connections"; it's what they call "stateless", meaning each request is separate from every other request. That's why we have things like session cookies; people had to hack in a way to allow information to be carried over between requests.

现在,即使它们是分开的,HTTP 1.1允许客户端发出多个请求通过相同的TCP / IP连接(尽管它是到HTTP服务器的连接,在TCP / IP堆栈中处于完整的其他级别)。请求仍然是独立的,但您不必打开新的网络连接。这允许一些效率提高,因为打开网络连接可能是昂贵的。

Now, even though they're separate, HTTP 1.1 allows a client to make multiple requests over the same TCP/IP connection (which, although it's a connection to an HTTP server, is at a whole other level in the TCP/IP stack). The requests will still be separate, but you don't have to open a new network connection. This allows some efficiency gains, as opening a network connection can be expensive.

如果你想利用这个,请观察请求和响应中的标题。如果请求使用的HTTP版本小于1.1,或者有一个标题为 连接:close ,那么在处理当前请求后连接将消失。否则,一旦清除(通常通过读取上一个请求中的所有数据),就可以重复使用。

If you'd like to take advantage of this, watch the headers in the request and response. If the request is using an HTTP version less than 1.1, or there's a header that says Connection: close, then the connection is to go away after the current request is handled. Otherwise, once it's been cleared out (usually by reading all the data from the previous request), it can be reused.

这篇关于在什么情况下关闭HTTP连接必要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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