Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does an HTTP 1.0 server close the connection?

Tags:

http

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.

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 "Connection reset by peer." 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?

like image 533
chacham15 Avatar asked Jul 03 '13 00:07

chacham15


People also ask

When should I close an HTTP 1.1 connection?

after the current request/response is complete. HTTP/1.1 applications that do not support persistent connections MUST include the "close" connection option in every message.

How long does HTTP connection stays open?

Persistent connections time out after 115 seconds (1.92 minutes) of inactivity which is changeable via the configuration.

Does HTTP close connection after request?

In HTTP 1.1 version, by default uses a persistent connection where it doesn't close automatically after a transaction. But the HTTP 1.0 will not consider the connections as persistent, so if you want to keep it alive, you need to include a keep-alive connection header.

Does HTTP keep connection open?

By default, HTTP connections close after each request. When someone visits your site, their browser needs to create new connections to request each of the files that make up your web pages (e.g. images, Javascript, and CSS stylesheets), a process that can lead to high page load times.


1 Answers

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.

like image 132
Remy Lebeau Avatar answered Sep 19 '22 06:09

Remy Lebeau