Connection Close for HTTP request response
Asked Answered
T

1

6

I have two questions on HTTP Connection close:

  1. If a client sends a HTTP request with Connection: close to HTTP Server, Is it the HTTP Server or client responsibility to send TCP FIN after response is received by client?

  2. If a client sends a bad formatted HTTP request, and server sends a 400 BAD REQUEST, is it best practice to close the connection by server (even though the HTTP request has connection: keep-alive) or is it good practice to keep the connection still active?

Thanks in advance for answering my queries?

Tribadism answered 5/8, 2014 at 7:34 Comment(1)
Have you tried these out using Fiddler (or similar) against a well known server?Firedrake
M
7
  1. When the server receives a 400 Bad Request, it is going to send the response with the keep-alive header because if the client feels like sending another request, then they can use a pre-existing connection (this connection is shut down within a certain amount of time, it has an expiration date). The Keep-Alive Header is more about not saturating the network with TCP connection demands. You basically say "I am going to talk to you, for 2 minutes, whatever you send me, I'll answer you though this connection"

  2. The server is only an object that receives commands from an user. You ask him, he does or not. The TCP FIN is something you send to the server to shut down the connection, but you choose when you don't want to communicate with him anymore. The client transmits the first FIN, and receives an ACK to ensure that the server got it. Then the server launches its own FIN, and waits for the ACK. If everything is okay, you and your server are no longer friends.

Mullock answered 5/8, 2014 at 7:52 Comment(4)
Thanks for detailed response. So, if a Request or response has header "Connection: Close", it is responsibility of the client to send TCP FIN to server to initiate the close of connection. Be it, this header is sent in a request by client or response by server. Is my understanding right here?Tribadism
The Connection: Close header is contained in the request and in the response whenever a closing of the connection is asked. You're right!Mullock
no, i use tcpdump and found don't like you said. i found always server to send FIN.Unrivalled
I am not sure, if you answered the first question? Who will close the connection ( or initiate the closing of connection ) if : 1. HTTP request has "Connection: close" in its header? 2. HTTP response has "Connection: close" in its header?Pelagic

© 2022 - 2024 — McMap. All rights reserved.