Requests, and responses are made up of two main parts, headers and a body. We briefly saw some HTTP headers when we used our TCP RFC downloader in Chapter 1, Network Programming and Python. Headers are the lines of protocol-specific information that appear at the beginning of the raw message that is sent over the TCP connection. The body is the rest of the message. It is separated from the headers by a blank line. The body is optional, its presence depends on the type of request or response. Here's an example of an HTTP request:
GET / HTTP/1.1 Accept-Encoding: identity Host: www.debian.com Connection: close User-Agent: Python-urllib/3.4
The first line is called the
request line. It is comprised of the request method, which is GET
in this case, the path to the resource, which is /
here, and the HTTP version, 1.1
. The rest of the lines are request headers. Each line is comprised of a header name followed by a colon and a header value. The request in the preceding output only contains...