Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent keep-alive in a HTTP 1.1 request?

I'm implementing a simple HTTP client.

Which header should I add to a HTTP 1.1 request so it won't keep alive?

like image 369
Gal Hyams Avatar asked Jun 25 '15 14:06

Gal Hyams


People also ask

Does HTTP 1.1 Use persistent connection?

A significant difference between HTTP/1.1 and earlier versions of HTTP is that persistent connections are the default behavior of any HTTP connection. That is, unless otherwise indicated, the client SHOULD assume that the server will maintain a persistent connection, even after error responses from the server.

Does HTTP 1.0 support keep-alive?

The HTTP 1.0 protocol does not support persistent connections by default. In order to do so, the client has to send a Connection header with its value set to keep-alive to indicate to the server that the connection should remain open for any subsequent requests.

What is the purpose of HTTP 1.1 keep-alive?

HTTP keep-alive, a.k.a., HTTP persistent connection, is an instruction that allows a single TCP connection to remain open for multiple HTTP requests/responses. By default, HTTP connections close after each request.


1 Answers

You need to add header: Connection: close. Currently all connections are permanent and client must explicitly claim that it wants to close the connection.

like image 133
Opal Avatar answered Sep 22 '22 17:09

Opal