
HTTP
- HTTP is a client-server protocol for fetching resources such as HTML documents.
- The client and server communicate by exchanging messages. Requests are initiated by the client(web browser).
- The messages sent by the client are called requests and the messages sent by the server as answers are called responses.
- HTTP is an application layer protocol that is sent over TCP or TLS-encrypted TCP connections, or UDP or any transport protocol can be used.
Components of HTTP-based systems
- A request is sent by a user agent. User-agent is a Web browser or it can be anything.
- This request is sent to a server, which handles it and gives an answer called a response.
- In between the client and the server, there are several entities called proxies.
- Proxies perform different operations and act as gateways or caches etc.
- There are more computers between a browser and the server handling the request: there are routers, modems and more.

The basic components of HTTP-based systems are:
- Client
- Web server
- Proxies
Client: the user-agent
- A user agent can be a browser, tool, or program used by web developers to debug an application.
- The browser is always initiating requests never the server.
- The browser sends an original request to fetch an HTML document.
- Then it parses the received file and makes additional requests to get the script, CSS files, images, videos, pdf, etc.
- The browser renders the fetched files and displays the web pages.
- Scripts are executed by the browser to fetch more resources and the browser updates the web page.
- Web pages contain links to other web pages, which are requested when we click them.
Web server
- A server is a computer that serves the resources requested by the client.
- A server appears to be a single machine but it is a collection of servers for load balancing, databases, caches etc.
- With HTTP/1.1 and the Host header, a single machine can host different software instances under the same IP address (Virtual Hosting).
Proxies
- Proxies are the relays between the user-agent and the web server.
- Due to the layered structure proxies are transparent at the HTTP layer and have an impact on performance.
- These are transparent because the requests received by the proxies are forwarded altering them.
- In some cases, proxies are non-transparent and will change the request before passing it to the server.
- Proxies perform functions like:
- Caching
- Filtering
- Load balancing
- authentication
- Logging
HTTP flow
Client-server request response steps:
1. A TCP connection is established to send requests and receive responses.
2. Send an HTTP message.
GET / HTTP/1.1
Host:example.com
Accept-Language: en
3. The response is as shown.
HTTP/1.1 200 OK
Date: Sat, 09 Oct 2010 14:28:02 GMT
Server: Apache
Last-Modified: Tue, 01 Dec 2009 20:18:22 GMT
ETag: "51142bc1-7449-479b075b2891b"
Accept-Ranges: bytes
Content-Length: 29769
Content-Type: text/html
<!doctype html>… (here come the 29769 bytes of the requested web page)
4. The connection is closed or kept alive for more requests.
HTTP messages
There are two types of HTTP messages they are requests and responses.
Requests
An example HTTP request:

Requests contain the following elements:
- An HTTP method like GET, POST, OPTIONS, DELETE etc.
- Path of the resource.
- The version of the HTTP protocol.
- Some headers and sometimes body also for the POST method.
Responses
An example HTTP request:

Responses consist of the following elements:
- The version of the HTTP protocol.
- A status code indicates whether the request is a success or not.
- A status message, a short description of the status code.
- HTTP headers.
- The body contains the resources.