HTTP 1.0服务器何时关闭连接? [英] When does an HTTP 1.0 server close the connection?

查看:97
本文介绍了HTTP 1.0服务器何时关闭连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我正在尝试让ApacheBench在我的自定义服务器上工作.我尝试发出 ab -n 1 -c 1 http://localhost:1337/index.html ,并且我嗅探了连接(使用wireshark),我发现有多个请求被发送了.

Background: I am trying to get ApacheBench working on my custom server. I tried issuing ab -n 1 -c 1 http://localhost:1337/index.html and I sniffing the connection (with wireshark) I see wayyy more than one request is sent.

示例请求:


GET /index.html HTTP/1.0
Host: localhost:1337
User-Agent: ApacheBench/2.3
Accept: */*

(repeats more times than I care to count)

我假设 RFC 1945 说:除实验应用外,目前的做法要求由客户端在每个请求之前建立连接,并在发送响应后由服务器关闭连接."当我请求一页时,它与ApacheBench一起使用.但是,如果我将请求数增加到10,则会收到对等方重置连接".考虑到我关闭了连接,这很有道理.

I assumed as RFC 1945 says "Except for experimental applications, current practice requires that the connection be established by the client prior to each request and closed by the server after sending the response." This works with ApacheBench when I request one page. However, if I up the number of requests to 10, I get "Connection reset by peer." This makes sense considering that I closed the connection.

但是,我在Google上尝试了相同的过程,并且在两种情况下都可以正常工作.那么,我应该如何知道何时关闭HTTP 1.0的连接?

I tried the same procedure with Google, however, and it works fine there for both cases. So, how am I supposed to know when to close the connection for HTTP 1.0?

推荐答案

在HTTP 0.9中,服务器总是在发送响应后关闭连接.客户端在收到响应后必须关闭其连接的末端.

In HTTP 0.9, the server always closes the connection after sending the response. The client must close its end of the connection after receiving the response.

在HTTP 1.0中,服务器总是在发送响应后关闭连接.除非,客户端发送了 Connection:keep-alive 请求标头,服务器发送了> Connection:保持活动状态响应标头.如果不存在这样的响应头,则客户端必须在收到响应后关闭其连接的末端.

In HTTP 1.0, the server always closes the connection after sending the response UNLESS the client sent a Connection: keep-alive request header and the server sent a Connection: keep-alive response header. If no such response header exists, the client must close its end of the connection after receiving the response.

在HTTP 1.1中,服务器在发送响应 UNLESS 后没有关闭连接,客户端发送了 Connection:close 请求标头,或者服务器发送了连接:关闭响应头.如果存在这样的响应头,则客户端必须在收到响应后关闭其连接的末尾.

In HTTP 1.1, the server does not close the connection after sending the response UNLESS the client sent a Connection: close request header, or the server sent a Connection: close response header. If such a response header exists, the client must close its end of the connection after receiving the response.

这篇关于HTTP 1.0服务器何时关闭连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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