28

When the client uses the Connection: close header in the request message, this means that it wants the server to close the connection after sending the response message.

I thought that this header is only used in the request messages, but I have noticed that it is also used in the response messages. For example:

enter image description here

What does this header means when used in the response message?

I think that it means that the server will close the connection after sending the response the message (even if the client has used the Connection: keep-alive header in its request message). Am I correct?

25

Yes, this is correct. The server can just say "I don't support your keep-alive request and will just close the connection when I am finished".

From RFC 2616, Section 14.10:

HTTP/1.1 defines the "close" connection option for the sender to
signal that the connection will be closed after completion of the
response. For example,

   Connection: close

in either the request or the response header fields indicates that the connection SHOULD NOT be considered `persistent' (section 8.1)
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.

  • 2
    That's weird IMO, why to say that the connection will be closed, if server can simply close it? Shouldn't client then just see it that the connection was closed by the server. Any idea what was the point in this header? I don't see any value here. – Pavel Nov 24 '18 at 5:43
  • 1
    @Pavel The web application includes the "Connection: close" http header in the response in cases where it want's to inform the front-end load balancer to close the keep alive connection incase the load balancer is using one. – Basil A Mar 12 at 13:59
  • @BasilA so that load balancer closes connection to the server or to the client? IMO load balancer could see that the connection was closed by the server and would know that without reading any headers. Also reverse is true: server can close connection without the Connection: close header – Pavel Mar 13 at 23:05
  • @Pavel The loadbalancer usually receives multiple connections from multiple clients and utilizes the same connection with the backend by using multiplexing through a keep-alive connection. When some backends might not want to be part of this multiplexing, the backend http response should include a "Connection: close" to inform the load balancer to close it's connection and stop multiplexing. This is described in detail in AWS Load Balancing Guide (Scroll down to 'HTTP Connections') docs.aws.amazon.com/elasticloadbalancing/latest/userguide/… – Basil A Mar 14 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.