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:
Content-Length
headerIn 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.
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.
Format of an HTTP RequestThe request ends with a bank line (an extra <CR><LF> or \r\n ).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With