The request object
HTTP request and response messages are similar, consisting of:
- A status line, which for a request would resemble GET/
index.html
HTTP/1.1, and for a response would resemble HTTP/1.1 200 OK - Zero or more headers, which in a request might include
Accept-Charset: UTF-8 or From: [email protected]
, and in responses might resembleContent-Type: text/html and Content-Length: 1024
- A message body, which for a response might be an HTML page, and for a POST request might be some form data
We've seen how HTTP server interfaces in Node are expected to expose a request handler, and how this handler will be passed some form of a request and response object, each of which implement a readable or writable stream.
We will cover the handling of POST data and Header data in more depth later in this chapter. Before we do, let's go over how to parse out some of the more straightforward information contained in a request.
The URL module
Whenever a request is made to an HTTP server the request...