Keep-Alive Header

Table of Content

  • Syntax
  • Directives
  • Examples
  • Browser Compatibility
  • How to modify Keep-Alive header The Keep-Alive Header is an HTTP/1.1 component of the HTTP protocol. Its functionality revolves around managing the connection between the client and the server. It was implemented to improve efficiency by allowing multiple requests to be sent over the same TCP connection without the overhead of opening a new one for each request. This helps to reduce latency and improve website performance overall.

Syntax

Connection: keep-alive
Keep-Alive: timeout=5, max=1000

Directives

The 'timeout' directive indicates how long the server should wait for subsequent requests before closing the connection. The 'max' directive states how many requests the server is willing to accept over the same connection.

For example, Keep-Alive: timeout=5, max=1000 would mean that the server would keep the connection open for 5 seconds and accept a maximum of 1000 individual requests over that connection.

Examples

An example using the Keep-Alive Header would look like this:

GET /index.html HTTP/1.1
Host: www.example.com
Connection: keep-alive
Keep-Alive: timeout=5, max=100

Browser Compatibility

Browser Compatibility
Chrome Supported
Firefox Supported
Safari Supported
Opera Supported
Edge Supported

How to modify Keep-Alive header

ModHeader is a handy Chrome extension for modifying HTTP headers. To use ModHeader to change the Keep-Alive Header, follow these steps:

  1. Install ModHeader from the Chrome Web Store.
  2. After installation, click on the ModHeader icon in the toolbar.
  3. In the 'Response headers' section, you can add new headers or modify existing ones.
  4. Enter 'Connection: keep-alive' in the 'name' field.
  5. In the 'value' field, enter 'Keep-Alive: timeout=X, max=Y' (where 'X' and 'Y' are your desired values).
  6. Apply the changes, and now your browser will send your custom Keep-Alive header with all requests.

This can be useful for testing the behavior of a website or web application under different Keep-Alive settings. For instance, you can adjust the timeout value to simulate a slow network connection and see how the application behaves.