HTTP Request Response Cycle


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


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.


GET / HTTP/1.1
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


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.


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


<head><title>Travis Luong</title></head>
  <h1>Hello, World!</h1>