You are previewing HTTP: The Definitive Guide.

HTTP: The Definitive Guide

Cover of HTTP: The Definitive Guide by David Gourley... Published by O'Reilly Media, Inc.
O'Reilly logo

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 ...

The best content for your career. Discover unlimited learning on demand for around $1/day.