joshft91
joshft91

Reputation: 1885

HTTP header and message body separator clarification

I'm going to be parsing metadata that will have the same format that HTTP headers/messages do.

I was reading RFC 2616 and I'm trying to understand this more clearly.

Is each HTTP header separated by CRLF (\r\n) and then the separator between the headers and the message body CRLFCRLF(\r\n\r\n)? I couldn't find (or maybe I missed it) anything that detailed what the standard was.

Thanks.

Upvotes: 7

Views: 24121

Answers (2)

CodeCaster
CodeCaster

Reputation: 151594

RFC 2616 (which you shouldn't look at anymore, 7230 is its successor) states:

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

So there's:

  1. The start-line, which is either a Request-Line or a Status-Line, both of which end in CRLF.
  2. Zero or more message-headers, each ending in CRLF.
  3. A CRLF to denote the end of the start-line and headers.
  4. Optionally, a message body.

That being said, you don't want to parse HTTP yourself. Use a library for that.

Example enter image description here (picture source)

Upvotes: 20

GideonMax
GideonMax

Reputation: 594

at the start of a message there is a request/status line.
other then that:
according to RFC2616, you are absolutely correct,
however, while RFC2616 specifies the headers' format as *(message-header CRLF)
RFC7230 specifies it as *( header-field CRLF )
apart from the name change, it doesn't seem to be any different, the format for the headers is the same.

tldr; yes.

p.s. parsing the headers for an http message is not that hard, took me a few hours, parsing the message body is mildly difficult but honestly, you should try doing it, it's a good challenge.

Upvotes: 0

Related Questions