Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 655
joshft91 Avatar asked Mar 18 '15 20:03

joshft91


People also ask

What is the difference between HTTP header and body?

A HTTP body (request) body is the one which carries actual HTTP request data (including form data and uploaded etc.) and HTTP response data from the server ( including files, images etc). While HTTP Request header header can't not contain actual data like as above.

What is HTTP message header?

HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon ( : ), then by its value.

How are HTTP request and response headers delimited?

The HTTP headers are used to pass additional information between the clients and the server through the request and response header. All the headers are case-insensitive, headers fields are separated by colon, key-value pairs in clear-text string format.


1 Answers

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)

like image 158
CodeCaster Avatar answered Oct 03 '22 10:10

CodeCaster