The Complete HTTP Request Lifecycle Explained Step-by-Step

Posted by Anonymous and classified in Computers

Written on in English with a size of 4.45 KB

1. Client Initiation and DNS Lookup

  • The user enters a URL or clicks a link in the browser. The browser parses the URL and extracts the domain (e.g., www.example.com).

  • A **DNS lookup** translates this domain into an IP address—acting like a digital phonebook entry.


2. Establishing the TCP Connection

The browser’s operating system (OS) creates a socket and initiates the **TCP three-way handshake** with the server:

  1. SYN: Client sends a synchronization request to the server.
  2. SYN-ACK: Server acknowledges the request and sends its own synchronization.
  3. ACK: Client acknowledges the server's response.

Once this handshake is complete, a full-duplex TCP connection is open and ready for reliable data exchange.


3. Sending the HTTP Request Message

The client constructs the HTTP request message, which typically comprises three main parts:

  • Request Line: Includes the method (e.g., GET, POST), the path/URI, and the protocol version.
  • Headers: Contains meta-information such as Host, User-Agent, cookies, and Content-Type.
  • Body: Required only for certain methods (e.g., POST) to carry data payload.

This message is serialized (usually plain text) and sent through the TCP socket. It is then re-packaged across the TCP/IP and Ethernet layers to be routed across the network.


4. Server Processing and Backend Logic

  • Upon arrival, the server extracts the HTTP message from the TCP/IP stack.

  • The server or web application parses the request, reads the method and URI, and invokes the necessary backend logic. This might involve serving a static file, executing database queries, or running application code via CGI/APIs.


5. Forming and Returning the HTTP Response

The server constructs the response message, which includes:

  • Status Line: Contains the HTTP version and the status code (e.g., 200 OK for success, 404 Not Found for errors).
  • Headers: Specifies meta-information like Content-Type, content length, and caching policies.
  • Body: The actual content requested (e.g., HTML document, JSON data, image file).

This response is sent back over the established TCP connection, traversing all network layers until it reaches the client.


6. Client Rendering and Connection Teardown

  • The browser receives the response, reads the headers (e.g., caching instructions), and begins rendering the content in the user interface (UI).

  • If additional resources are required (such as CSS files or JavaScript scripts), the browser issues new HTTP requests, often reusing the existing TCP connection via **HTTP Keep-Alive**.

  • Eventually, when interactions are complete, either the client or the server sends a TCP FIN (Finish) flag to gracefully close the connection.


7. HTTPS: The Secure Layer (TLS Handshake)

  • If the URL uses **HTTPS**, an additional **TLS handshake** (Transport Layer Security) must occur before the HTTP request is sent, effectively wrapping the TCP connection.

  • This process encrypts all subsequent HTTP messages, ensuring protection against eavesdropping and data tampering.


HTTP Request Lifecycle Summary

StepWhat Happens
DNS LookupTranslates the domain name into an IP address.
TCP HandshakeClient and server establish a reliable connection using SYN ⬌ SYN-ACK ⬌ ACK.
HTTP RequestBrowser sends the request line, headers, and body over the TCP connection.
Server ProcessingServer decodes the request, processes backend logic, and prepares content.
HTTP ResponseServer returns the status line, response headers, and the content body.
Browser RenderingClient parses the response, displays content, and may initiate further requests.
Connection TeardownThe TCP connection is closed using the FIN/ACK exchange.

Related entries: