HTTP Request Response Cycle

12.27.2014

The request-response cycle begins with a client sending a request message to a server. The server handles the request and sends a response message back to the client. An HTTP message has a header and sometimes a body. The header contains meta-information about the message. The body contains the content.

http request response cycle

Request

The request header consists of the request line, host, and name-value pairs (header fields). The request line contains the HTTP method and request-URI.

Header

GET / HTTP/1.1
Host: www.travisluong.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:34.0) Gecko/20100101 Firefox/34.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0

Response

The response header consists of a status line and name-value pairs. The status line provides a status code which tells you if the request was successful or not. There are many status codes with different meanings.

Header

HTTP/1.1 200 OK
Date: Sat, 20 Dec 2014 08:17:22 GMT
Server: Apache
Cache-Control: max-age=3600
Expires: Sat, 20 Dec 2014 09:17:22 GMT
Vary: User-Agent,Accept-Encoding
Content-Type: text/html; charset=UTF-8

Body

<html>
<head><title>Travis Luong</title></head>
<body>
  <h1>Hello, World!</h1>
  <p>foo</p>
</body>
</html>

Sources

http://docstore.mik.ua/orelly/linux/cgi/ch02_02.htm
http://perl.plover.com/yak/presentation/samples/security/slide012.html
http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
http://www.w3.org/Protocols/rfc2616/rfc2616.html
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html