Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

End of an HTTP Response

What indicates the end of an HTTP Response, without having a Content-Length header?

I've read that in some case, that server closes the TCP connection. But I've witnessed cases that the TCP Connection existed after receiving all the response.

So a major problem arises when:

  • There isn't a Content-Length header
  • TCP connection exist after receiving all of the HTTP Response
  • The browser wishes to use the same TCP connection in order to send more HTTP Requests

In that case, how the browser knows it can use the same TCP connection? The server might send more content that's relevant to the 1'st HTTP Request and that would get mixed up with the 2'nd HTTP Response.

like image 279
Dor Avatar asked Jul 07 '13 19:07

Dor


People also ask

What is the end HTTP response?

end() Method. The httpServerResponse. end() is an inbuilt application programming interface of class Server Response within http module which is used to send the signal to the server that all the header has been sent.

How do you end an HTTP request?

Format of an HTTP RequestThe request ends with a bank line (an extra <CR><LF> or \r\n ).

How does HTTP end a message body?

Answer: SMTP uses a line containing only a period to mark the end of a message body. HTTP uses “Content-Length header field” to indicate the length of a message body.

What is the body of an HTTP response?

An HTTP response has both a header and a body. The header info tells the browser about the protocol being used, whether the request was successful, and what kind of content is included in the body. The body contains the contents (for example, HTML) for the browser to display.


1 Answers

If both the client and the server support HTTP 1.1, and the server does not know the response body size in advance (and therefore cannot send the Content-Length response header), the server should use chunked encoding, which allows the client to find the end of the response body even if the server does not close the TCP connection immediately after sending the response.

If HTTP 1.1 cannot be used (because either the client or the server is too old), the chunked encoding cannot be used, and in such cases sending a response without the Content-Length header prevents the server from keeping the TCP connection persistent.

like image 76
Sergey Vlasov Avatar answered Oct 11 '22 23:10

Sergey Vlasov