Search code examples
httphttpresponse

Is there a CRLF after the message-body?


I don't know if after sending all the bytes of the body I should send the next message without a CRLF separating the body of the first message from the start-line of the second message.

This is the syntax according to RFC 7230:

 HTTP-message   = start-line
                  *( header-field CRLF )
                  CRLF
                  [ message-body ]

According to the syntax there is no CRLF at the end of the body, but it looks odd since everything else seems to be separated by a CRLF specially the syntax for the chunked body.

 chunk          = chunk-size [ chunk-ext ] CRLF
                  chunk-data CRLF

This is how it looks without the CRLF:

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 3

abcHTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 3

And this is how it would look with it:

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 3

abc
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 3

abc

So, should a CRLF follow the body?


Solution

  • It is easier for me to read with the CRLF.

    Then you must include it in the message body:

    RFC 7230, 3.5. Message Parsing Robustness:

    An HTTP/1.1 user agent MUST NOT preface or follow a request with an extra CRLF. If terminating the request message body with a line-ending is desired, then the user agent MUST count the terminating CRLF octets as part of the message body length.