When sending a HTTP Response, should I conclude the response body (the content itself) with a newline (line separator)?
And if so, should I include the size of the line separator (I guess increase the count with 2 if sending \r\n) in the Content-Length?
NO!
The resource data that is being sent in the HTTP response's message-body may include its own newlines (as is common in text files, etc), but that is arbitrary data as far as HTTP itself is concerned. Newlines inside the message-data are NOT part of the HTTP response itself. The HTTP response is terminated by reaching the
Content-Length
(which is the byte size of the resource data) unlessTransfer-Encoding
is used (in which caseContent-Length
is ignored, and thechunked
encoding is used, which is self-terminating), or the connection is closed at the end of the response. This is described in RFC 2616 Section 4.4:I don't see anything like this in RFC 2616:
There are two newlines in a response, both are at the end of the headers, not at the end of the message-body. The headers will describe how the message-body is terminated.
The RFC doesn't require you to send a newline. The message length is not calculated based on the presence of such a newline. See Message Length section which describes how the message length is calculated.