Sobes.tech
Junior — Middle

Is persistent connection supported in the HTTP/1.1 protocol?

sobes.tech AI

Answer from AI

Yes, HTTP/1.1 protocol supports persistent connections by default. This means that after transmitting one HTTP request and response, the TCP connection is not automatically closed but remains open for subsequent requests.

To manage persistent connections, headers are used:

  • Connection: keep-alive — explicitly indicates the desire to keep the connection open.
  • Connection: close — signals to close the connection after the current request.

In Go, the standard net/http library supports persistent connections by default, which improves performance by reusing TCP connections.

Example of using a client with keep-alive:

client := &http.Client{}
resp, err := client.Get("http://example.com")
// the connection will be reused for subsequent requests
Is persistent connection supported in the HTTP/1.1… - sobes.tech