When does an HTTP 1.0 server close a connection?

Reference Information. I am trying to get ApacheBench to work on my custom server. I tried issuing ab -n 1 -c 1 http://localhost:1337/index.html and I sniffed the connection (using wirehark). I see more than one request being sent.

Request example:

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

 (repeats more times than I care to count)

I suggested that RFC 1945 says: β€œWith the exception of experimental applications, current practice requires that a connection be established by the client before each request and closed by the server after the response is sent.” This works with ApacheBench when I request a single page. However, if I increase the number of requests to 10, I get "Connection reset by peer". This makes sense, given that I closed the connection.

I tried the same procedure with Google, but it works great for both cases. So, how should I know when to close the connection for HTTP 1.0?

+4
source share
1 answer

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 a response.

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

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

+13
source

Source: https://habr.com/ru/post/1489384/


All Articles