
HTTP
1.1 HTTP in a nutshell:
- HTTP is the protocol used to send and receive information between a client (browser) and a server.
- The browser will send a request message to the server requesting a resource which can be a webpage, images,scripts, style-sheets etc
- The servers responds by sending back the requested resource to the browser.
- This communication takes place as a Request- Response Cycle.
- The communication takes place mostly over TCP/IP.
- HTTP is a stateless protocol, which means it does not store information about the request sent.
- It is a text-based protocol (more on this soon)
- Its responses have a status code (more on this soon).
1.2 Anatomy of a Request-Response Cycle:
[image taken from Here, highly recommended reading]
1.3 Anatomy of a request message
When you type in an address in the address bar of your browser or an IP address. The browser translates the URL into a request message with the following parts:
1. Request line:
- Structured as: Request Method Name/ Request URI / HTTP-version
- For example:
GET /test.html HTTP/1.1 HEAD /query.html HTTP/1.0 POST /index.html HTTP/1.1
2. Request header: Formatted as name : value pairs:
Host: www.google.com
Accept: image/gif, image/jpeg
User Agent: Mozilla/4.0
Accept-language: en-us
Content-length: 33
3. A blank line that separates the header and body
4. Request body (optional):
bookId=13&author=Kauress
Check out: http://web-sniffer.net/ to view the parts of a request message
1.4 Anatomy of a response message
When the server receives the request, it will read it and a response message is structured with the following parts:
1. Status Code:
- Structured as: HTTP-version/ status-code/explanation of the status code
- For example:
HTTP/1.1 200 OK HTTP/1.0 404 Not Found HTTP/1.1 403 Forbidden
2. Response Header
- Formatted as name value pairs
- For example:
Content-Type: text/html Content-Length: 100 Connection: Keep-Alive Keep-Alive: timeout=15, max=100
3. A blank line that separates the header and body
4. Response body : Contains the content of the web page that is being sent back to the browser to be displayed to the user. For example
<h1>Hello World!</h1>