Search code examples
http

When does an HTTP 1.0 server close the connection?


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 when I sniff the connection (with WireShark) I see way more than one request is sent.

Example Request:

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

(repeats more times than I care to count)

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 a "Connection reset by peer" error. This makes sense considering that I closed the connection.

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?


Solution

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

    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.

    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.