Step 2: Receiving Request Messages

As the data arrives on connections, the web server reads out the data from the network connection and parses out the pieces of the request message (Figure 5-5).

Reading a request message from a connection

Figure 5-5. Reading a request message from a connection

When parsing the request message, the web server:

  • Parses the request line looking for the request method, the specified resource identifier (URI), and the version number,[3] each separated by a single space, and ending with a carriage-return line-feed (CRLF) sequence[4]

  • Reads the message headers, each ending in CRLF

  • Detects the end-of-headers blank line, ending in CRLF (if present)

  • Reads the request body, if any (length specified by the Content-Length header)

When parsing request messages, web servers receive input data erratically from the network. The network connection can stall at any point. The web server needs to read data from the network and temporarily store the partial message data in memory until it receives enough data to parse it and make sense of it.

Internal Representations of Messages

Some web servers also store the request messages in internal data structures that make the message easy to manipulate. For example, the data structure might contain pointers and lengths of each piece of the request message, and the headers might be stored in a fast lookup table so the specific values of particular headers can be accessed quickly ...

Get HTTP: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.