Back to series
· 19 min read

The Complete Network Request Chain: From URL Entry to Page Rendering


1. Starting from URL Input: What Happens During a Network Request?

When the user enters the following in the browser address bar:

https://www.example.com/articles/network

and then presses Enter, the browser must complete a series of tasks before it can turn the data returned by the server into the final page.

At a high level, the whole process can be divided into several stages:

  1. URL parsing: identify the protocol, domain, port, and path.
  2. Browser preparation: check mechanisms such as cache, Service Worker, and HSTS.
  3. DNS resolution: resolve the domain name to an IP address.
  4. Network connection: establish a TCP or QUIC connection.
  5. TLS handshake: negotiate encryption parameters and verify the server's identity.
  6. HTTP request: send request headers and request body.
  7. Server-side processing: perform routing, authentication, business logic, and data queries.
  8. HTTP response: return the status code, response headers, and response body.
  9. Browser parsing: parse HTML, CSS, JavaScript, and other resources.
  10. Page rendering: build the DOM, CSSOM, and layout tree, and paint the page.

The overall flow is as follows:

flowchart TD
    A["User enters URL"] --> B["Browser parses URL"]
    B --> C["Check browser cache and Service Worker"]
    C --> D{"Can the local response be used directly?"}
    D -->|"Yes"| E["Get local response"]
    D -->|"No"| F["Resolve domain name via DNS"]
    F --> G["Establish network connection"]
    G --> H["TLS handshake and protocol negotiation"]
    H --> I["Send HTTP request"]
    I --> J["Server processes request"]
    J --> K["Return HTTP response"]
    K --> L["Parse HTML and resources"]
    E --> L
    L --> M["Build DOM and CSSOM"]
    M --> N["Layout, paint, and composite"]
    N --> O["Page display"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style D fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style E fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style H fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style I fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style J fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style K fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style L fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style M fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style N fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style O fill:#E0F0FE,stroke:#93BCE8,color:#1E4976

Note that this is a typical access path; not every request goes through every stage in full.

For example:

  • When the browser cache is hit, it may not need to access the server.
  • A Service Worker can directly return a cached response.
  • DNS results may already be cached.
  • A TCP or QUIC connection may already be established and can be reused directly.
  • A TLS session may be resumed, so a full handshake is not required.
  • The page may display existing content first and then load other resources asynchronously.

Understanding these differences is the foundation for analyzing network request performance and failures.

2. Step One: URL Parsing

First, the browser needs to understand the URL entered by the user.

URL stands for Uniform Resource Locator; it describes the location of a resource and how to access it.

2.1 Basic Structure of a URL

For example:

https://www.example.com:443/articles/network?id=100&page=2#section-3

It can be broken down into:

Component Example Meaning
Scheme https Protocol used
Host www.example.com Target hostname
Port 443 Target port
Path /articles/network Resource path
Query id=100&page=2 Query parameters
Fragment section-3 Page fragment identifier

The general structure of a URL:

scheme://userinfo@host:port/path?query#fragment

Where:

  • scheme: the access protocol.
  • userinfo: an optional user information section; in modern applications it is not recommended for carrying sensitive credentials.
  • host: the domain name or IP address.
  • port: the port.
  • path: the resource path.
  • query: the query parameters.
  • fragment: the fragment identifier.

2.2 How does the browser parse a URL?

The browser parses the input according to URL syntax, and combines it with the current page context to handle relative addresses, default protocols, and other navigation rules.

For example:

const url = new URL(
  "https://www.example.com:443/articles/network?id=100"
);

console.log(url.protocol);
console.log(url.hostname);
console.log(url.port);
console.log(url.pathname);
console.log(url.search);
console.log(url.hash);

Output:

https:
www.example.com

/articles/network
?id=100

Because the default port for HTTPS is 443, the browser may omit the default port when normalizing the URL.

2.3 The difference between a URL and a URI

A URI is a uniform resource identifier, and a URL is a type of URI.

  • URI: used to identify a resource.
  • URL: further describes the access location or addressing method of the resource.

You can think of it as: URLs fall within the scope of URIs, but not every URI can be used directly as a network access address.

2.4 Why is the fragment not sent to the server?

For example:

https://www.example.com/index.html#chapter-2

When the browser initiates an HTTP request, it does not send #chapter-2 to the server as part of the request target.

The server typically only receives:

GET /index.html HTTP/1.1
Host: www.example.com

The fragment is handled primarily by the browser on the client side, where it is used to locate page content or drive front-end routing.

This is also why changing a URL's fragment usually does not trigger a full HTTP request.

2.5 Default ports for HTTP and HTTPS

Protocol Default port
HTTP 80
HTTPS 443
FTP 21
SSH 22
DNS 53

Ports are used to identify network services on the target host.

The browser uses the protocol and port to determine the access method and the connection target.

III. Step Two: Browser Preparation and Cache Checking

Once URL parsing is complete, the browser does not necessarily access the network right away.

It first considers whether the request can be completed using existing data and existing connections.

3.1 Browser cache

Browser caching can reduce the overhead of repeatedly downloading resources.

Common cache types:

Cache type Description
Memory cache Resources stored in the memory of the browser process
Disk cache Resources stored on the local disk
HTTP cache Resources managed according to HTTP caching rules
Service Worker Cache Cache managed by a Service Worker
BFCache Stores page snapshots, used to restore pages on forward and back navigation

These caching mechanisms are not entirely the same system.

For example, BFCache stores a snapshot of the page state, not an ordinary HTTP resource cache.

3.2 HTTP Caching Mechanisms

HTTP caching is mainly divided into strong caching and negotiated caching.

Strong caching

Strong caching allows the browser to use local resources directly within the validity period without having to verify with the server whether the resource has changed.

Common response header:

Cache-Control: max-age=3600

This means the response can be used directly within the specified freshness lifetime.

Other common directives:

Directive Meaning
max-age=3600 The response stays fresh for 3600 seconds
no-cache Validation is required before use
no-store The response should not be stored
private May only be stored by a private cache
public May be stored by a shared cache
must-revalidate Must be revalidated once stale

Note: no-cache does not mean no caching; it usually means validation is required before use.

Negotiated caching

When a cached resource needs to be revalidated, the browser can send a conditional request to the server.

Common approach one: ETag.

The server returns:

HTTP/1.1 200 OK
ETag: "abc123"

The browser requests again:

GET /app.js HTTP/1.1
If-None-Match: "abc123"

If the resource has not changed, the server can return:

HTTP/1.1 304 Not Modified

The browser continues to use the locally cached content.

Common approach two: Last-Modified.

The server returns:

Last-Modified: Fri, 04 Dec 2026 10:00:00 GMT

The browser requests again:

If-Modified-Since: Fri, 04 Dec 2026 10:00:00 GMT

If the resource has not changed, the server returns 304 Not Modified.

3.3 Strong Caching and Negotiated Caching Flow

flowchart TD
    A["Browser requests resource"] --> B{"Is there a local cache?"}
    B -->|"No"| C["Send request to server"]
    B -->|"Yes"| D{"Is the cache still fresh?"}
    D -->|"Yes"| E["Use local cache directly"]
    D -->|"No"| F["Send conditional request"]
    F --> G{"Server determines whether resource has changed"}
    G -->|"Unchanged"| H["Return 304"]
    G -->|"Changed"| I["Return 200 and new resource"]
    H --> J["Use local cached content"]
    I --> K["Update local cache"]
    C --> I

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style C fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style D fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style E fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style H fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style I fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style J fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style K fill:#F0EAFE,stroke:#B7A1E8,color:#334155

3.4 Service Worker

A Service Worker is an independent script running in the browser background that can intercept matching network requests.

It can:

  • Return cached resources from Cache Storage.
  • Access the network and cache responses.
  • Choose different strategies based on the request type.
  • Return an offline page when the network is unavailable.
  • Provide offline capabilities for PWAs.

Typical request flow:

flowchart TD
    A["Page initiates a Fetch request"] --> B["Service Worker intercepts"]
    B --> C{"Match caching strategy"}
    C -->|"Cache first"| D["Query Cache Storage"]
    C -->|"Network first"| E["Initiate network request"]
    D --> F{"Cache hit?"}
    F -->|"Yes"| G["Return cached response"]
    F -->|"No"| E
    E --> H{"Is network request successful?"}
    H -->|"Yes"| I["Return network response and cache according to strategy"]
    H -->|"No"| J["Execute offline fallback strategy"]
    I --> K["Page receives response"]
    G --> K
    J --> K

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style D fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style G fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style H fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style I fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style J fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style K fill:#E0F0FE,stroke:#93BCE8,color:#1E4976

Note that a Service Worker must meet secure context requirements, which usually requires HTTPS; localhost in a development environment is a common exception.

3.5 HSTS: Automatic HTTPS Upgrade

HSTS, short for HTTP Strict Transport Security, is a browser security mechanism.

The server can tell the browser through a response header:

Strict-Transport-Security: max-age=31536000; includeSubDomains

After the browser records this policy, it upgrades qualifying HTTP requests to HTTPS for the policy's validity period.

HSTS can reduce the risk of protocol downgrade and some man-in-the-middle attacks.

It is not equivalent to HTTP caching, nor does it directly cache page resources.

IV. Step 3: DNS Domain Name Resolution

If the browser needs to access the network and does not yet have a usable destination IP address, it must resolve the domain name.

For example:

www.example.com

Computer network communication ultimately requires an IP address to locate the destination host.

DNS, short for Domain Name System, is responsible for resolving domain names into resource records such as IP addresses.

4.1 Why is DNS needed?

Humans find domain names easier to remember:

www.example.com

Computer networks use IP addresses for addressing:

93.184.216.34

DNS associates easy-to-read domain names with network addresses.

4.2 What components are involved in DNS resolution?

Component Role
Browser DNS cache Stores recent resolution results
Operating system DNS cache Stores system-level resolution results
Hosts file Local static domain name mappings
DNS stub resolver Initiates queries to the configured DNS server
Recursive DNS resolver Performs recursive queries on behalf of the client
Root DNS server Points to the corresponding top-level domain servers
TLD DNS server Manages top-level domain information
Authoritative DNS server Provides authoritative records for the domain name

4.3 DNS query process

Suppose the browser needs to resolve:

www.example.com

If no usable result is available locally, the recursive resolver may query the following in order:

  1. The root DNS server.
  2. The .com top-level domain DNS server.
  3. The example.com authoritative DNS server.
sequenceDiagram
    participant C as Client
    participant R as Recursive DNS Resolver
    participant Root as Root DNS Server
    participant TLD as .com TLD Server
    participant Auth as Authoritative DNS Server

    C->>R: Query www.example.com
    Note over R: Check cache
    R->>Root: Query root zone information
    Root-->>R: Return .com server addresses
    R->>TLD: Query example.com
    TLD-->>R: Return authoritative DNS server address
    R->>Auth: Query www.example.com
    Auth-->>R: Return A or AAAA record
    R-->>C: Return resolution result

This is the typical process in which a recursive resolver performs iterative queries.

Actual DNS queries may differ due to caching, delegation relationships, CNAME chains, DNS forwarding, and other factors.

4.4 Common DNS record types

Record type Role Example
A Maps a domain name to IPv4 93.184.216.34
AAAA Maps a domain name to IPv6 2001:db8::1
CNAME Alias record www -> cdn.example.net
MX Mail server mail.example.com
NS Name server ns1.example.com
TXT Text information SPF, verification information
SRV Service location Host, port, and priority
HTTPS HTTPS service connection parameters Service endpoints and connection hints

4.5 DNS caching

DNS has a caching mechanism that can reduce repeated queries.

Common cache locations:

  • The browser.
  • The operating system.
  • Local DNS forwarders.
  • Recursive DNS resolvers.

DNS records usually include a TTL, which indicates how long the cache may retain them.

For example:

www.example.com. 300 IN A 93.184.216.34

Here, 300 means the TTL is 300 seconds.

Note the following:

  • TTL is an important basis for determining how long a cache remains valid.
  • A TTL that is too long delays the effect of DNS changes.
  • A TTL that is too short increases the volume of DNS queries.
  • Different DNS cache implementations may apply additional policies.

4.6 Does DNS querying use UDP or TCP?

Traditional DNS typically uses UDP port 53.

However, DNS also uses TCP, for example:

  • The response data is large and requires TCP transmission.
  • Zone transfers.
  • Certain specific queries and network environments.

In addition, there are:

  • DoT: DNS over TLS.
  • DoH: DNS over HTTPS.
  • DoQ: DNS over QUIC.

They protect DNS query communication through different transport methods.

4.7 How to View DNS Resolution?

Linux or macOS:

nslookup www.example.com

You can also use:

dig www.example.com

View the A record:

dig A www.example.com

View the AAAA record:

dig AAAA www.example.com

View the complete resolution process:

dig +trace www.example.com

V. Step 4: Establish a Network Connection

After obtaining the server's IP address, the browser needs to establish a network connection.

If accessing HTTP/1.1 or HTTP/2, TCP is usually used.

If accessing HTTP/3, QUIC is used, and QUIC is based on UDP.

5.1 Establishing a TCP Connection

TCP is a connection-oriented, reliable transport protocol.

Establishing a TCP connection usually requires a three-way handshake.

sequenceDiagram
    participant C as Client
    participant S as Server

    C->>S: SYN
    Note over C: The client sends a connection request
    S-->>C: SYN ACK
    Note over S: The server acknowledges and sends its own sequence number
    C->>S: ACK
    Note over C,S: TCP connection established

The purpose of the three-way handshake:

  1. The client tells the server that it wants to establish a connection.
  2. The server acknowledges the client's request and informs the client of its own initial sequence number.
  3. The client acknowledges the server's response.

After the TCP connection is established, both parties can use it to transmit a reliable byte stream.

5.2 Why Is a Three-Way Handshake Needed?

TCP needs to confirm the sending and receiving capabilities of both parties.

The three-way handshake helps both parties synchronize initial sequence numbers and confirm the conditions for bidirectional communication during connection establishment.

If there were only two handshakes, the server could not reliably confirm whether the client had received its connection acknowledgment.

In addition, the three-way handshake can reduce interference from stale delayed connection requests on new connections.

5.3 What Identifies a TCP Connection?

A TCP connection can usually be identified by a four-tuple:

Source IP address
Source port
Destination IP address
Destination port

For example:

192.168.1.10:52000
    ->
93.184.216.34:443

The same client can establish multiple TCP connections with the same server, as long as the connection identifiers do not conflict.

5.4 QUIC and HTTP/3

HTTP/3 does not use TCP; instead, it runs on top of QUIC.

QUIC is based on UDP, but it implements reliable transport, congestion control, stream management, and encrypted handshake capabilities itself.

To put it simply:

flowchart TD
    A["HTTP/1.1 or HTTP/2"] --> B["TCP"]
    B --> C["IP"]
    D["HTTP/3"] --> E["QUIC"]
    E --> F["UDP"]
    F --> C

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style D fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style E fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F

The advantages of QUIC include:

  • Reduced latency in some connection establishment.
  • Better transmission isolation between multiple streams.
  • Support for connection migration.
  • TLS 1.3 security mechanisms are integrated into the protocol handshake.

QUIC does not mean that UDP itself has become a reliable protocol; rather, reliable transport capabilities are implemented by QUIC on top of UDP.

VI. Step 5: TLS Handshake and HTTPS Encryption

After the TCP connection is established, if HTTPS is being accessed, the client and server also need to complete a TLS handshake.

TLS, short for Transport Layer Security, is a security protocol used to protect network communications.

It mainly provides:

  • Identity authentication.
  • Data confidentiality.
  • Data integrity.
  • Secure key negotiation.

6.1 Purpose of the TLS Handshake

The TLS handshake needs to solve several problems:

  1. What TLS version do both parties use?
  2. What cipher suites or cryptographic algorithms are used?
  3. How does the server prove its identity?
  4. How do both parties negotiate the session key?
  5. How is subsequent data encrypted and verified?

6.2 The TLS 1.3 Handshake Process

A typical full TLS 1.3 handshake:

sequenceDiagram
    participant C as Client
    participant S as Server

    C->>S: ClientHello
    Note over C,S: Includes supported versions, cipher suites, and key share parameters
    S-->>C: ServerHello
    Note over S: Selects cipher parameters and sends key share information
    S-->>C: EncryptedExtensions
    S-->>C: Certificate
    S-->>C: CertificateVerify
    S-->>C: Finished
    Note over C: Verifies the server certificate and handshake data
    C->>S: Finished
    Note over C,S: Handshake complete, encrypted communication begins

TLS 1.3 generates the session key through a key agreement mechanism.

Afterwards, HTTP data is usually protected using efficient symmetric encryption algorithms.

6.3 The Role of Digital Certificates

The server provides a digital certificate to the client.

A certificate typically contains:

  • Domain name information.
  • Certificate holder information.
  • Public key.
  • Certificate validity period.
  • Issuer information.
  • Digital signature.
  • Extension fields.

The browser checks whether the certificate chain is trusted and verifies whether the domain being accessed matches the certificate.

For example:

Domain being accessed:
www.example.com

Domain in the certificate:
www.example.com

If the certificate's domain does not match, the browser may display a security warning.

6.4 Why Is a Certificate Chain Needed?

Browsers generally do not directly trust arbitrary server certificates.

Instead, they verify the trust relationship through a certificate chain:

flowchart TD
    A["Server Certificate"] --> B["Intermediate CA Certificate"]
    B --> C["Root CA Certificate"]
    C --> D["Browser Trust Store"]
    D --> E["Establish Trust Decision"]
    E --> F{"Is the certificate chain trusted?"}
    F -->|"Yes"| G["Continue TLS handshake"]
    F -->|"No"| H["Report certificate verification failure"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style D fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style E fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style F fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style G fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style H fill:#FCE8E6,stroke:#E6A6A1,color:#7B3E3A

6.5 ALPN: Negotiating the HTTP Protocol Version

The TLS handshake may also negotiate an application-layer protocol.

ALPN stands for Application-Layer Protocol Negotiation.

Common identifiers:

Identifier Protocol
http/1.1 HTTP/1.1
h2 HTTP/2
h3 The protocol identification scheme for HTTP/3, typically negotiated through the QUIC/TLS mechanism

For TLS-based HTTP/1.1 and HTTP/2, ALPN is the common negotiation method.

HTTP/3 runs on QUIC, and it cannot simply be understood as first establishing TCP/TLS and then negotiating HTTP/3. Its protocol negotiation is integrated with the QUIC handshake.

In addition, the fact that the client and server support a certain version does not mean that version will definitely be used in the end; it also depends on intermediate networks, proxies, and actual deployment capabilities.

7. Step Six: The Browser Sends an HTTP Request

Once the connection and security negotiation are complete, the browser can send an HTTP request.

HTTP is an application-layer protocol that defines how the client expresses a request and how the server returns a response.

7.1 The HTTP Request Message

Taking HTTP/1.1 as an example:

GET /articles/network?id=100 HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html,application/xhtml+xml
Accept-Language: zh-CN,zh;q=0.9
Accept-Encoding: gzip, br
Cookie: session=example-session
Connection: keep-alive

An HTTP/1.1 request mainly consists of the following parts:

  1. Request line.
  2. Request headers.
  3. Blank line.
  4. Request body, optional.

7.2 HTTP Request Methods

Common request methods:

Method Purpose
GET Retrieve a resource
POST Submit data or perform an action
PUT Create or fully replace a resource
PATCH Partially update a resource
DELETE Delete a resource
HEAD Retrieve response headers without returning a response body
OPTIONS Query communication options

For example, when a browser submits a login form:

POST /api/login HTTP/1.1
Host: www.example.com
Content-Type: application/json

{
  "username": "alice",
  "password": "example-password"
}

In real production environments, sensitive data such as passwords must be transmitted over HTTPS, and the server must also handle secure storage and authentication processing.

7.3 The Role of Request Headers

Request headers describe the context of the request.

Request Header Purpose
Host Specifies the target host
User-Agent Describes client information
Accept Declares acceptable media types
Accept-Encoding Declares supported content encodings
Authorization Provides authentication information
Cookie Sends cookies that match the applicable rules
Origin Indicates the origin of the request
Referer Indicates the referring page
Content-Type Describes the media type of the request body
Content-Length Describes the length of the request body

HTTP/2 and HTTP/3 use different binary framing structures and header encoding schemes, but the request methods, status codes, and header semantics at the HTTP semantic layer remain largely consistent.

7.4 HTTP Requests and TCP Packets Are Not the Same Thing

An HTTP request is application-layer data.

It may go through the following processing:

flowchart TD
    A["HTTP request"] --> B["HTTP protocol encoding"]
    B --> C["TLS encryption"]
    C --> D["TCP byte stream"]
    D --> E["TCP segmentation"]
    E --> F["IP packet"]
    F --> G["Link-layer frame"]
    G --> H["Network transmission"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style D fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style E fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style H fill:#F1F5F9,stroke:#CBD5E1,color:#334155

Notes:

  • A single HTTP request may be split across multiple TCP segments.
  • A single TCP segment does not necessarily correspond to one complete HTTP request.
  • TLS encrypts and encapsulates application data.
  • HTTP/2 and HTTP/3 also have their own frame and stream mechanisms.

Therefore, you cannot simply assume that one HTTP request equals one TCP packet.

8. Step Seven: Data Travels Across the Network to the Server

After an HTTP request is sent, the data must travel through network devices to reach the target server.

8.1 Where Does the Data Start From?

In a typical home network environment, the communication path may pass through:

  1. The browser process.
  2. The operating system network protocol stack.
  3. The network interface card.
  4. The home router.
  5. The ISP network.
  6. The backbone network.
  7. The target network entry point.
  8. A load balancer or CDN.
  9. The server.
flowchart TD
    A["Browser process"] --> B["OS network protocol stack"]
    B --> C["NIC"]
    C --> D["Home router"]
    D --> E["ISP network"]
    E --> F["Internet backbone"]
    F --> G["Target network entry"]
    G --> H["CDN or load balancer"]
    H --> I["Target server"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style D fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style E fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style H fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style I fill:#DCEFE5,stroke:#8EBFA5,color:#24563F

The actual network path depends on network topology, routing policies, CDN nodes, and ISP interconnection conditions.

8.2 What Is the Role of an IP Address?

The IP protocol is responsible for transmitting packets between networks.

It mainly involves:

  • Source IP address.
  • Destination IP address.
  • Routing and forwarding.
  • Fragmentation or path MTU-related mechanisms.
  • TTL or Hop Limit.

For example:

Source IP:
192.168.1.10

Destination IP:
93.184.216.34

A router determines the next hop based on the destination IP and the routing table.

8.3 What Is the Role of a MAC Address?

MAC addresses are mainly used for link-layer communication.

When data needs to be sent on the local network, the device needs to determine the link-layer address of the next hop.

In IPv4 networks, ARP is commonly used to resolve the MAC address corresponding to a destination IPv4 address.

If the destination IP is not on the local subnet, the client typically sends the data frame to the default gateway rather than directly to the MAC address of the remote server.

8.4 The Role of NAT

Home routers typically use NAT to map private network addresses to public addresses.

For example:

Private network:
192.168.1.10:52000

Public mapping:
203.0.113.10:62000

The NAT device maintains address and port mappings, allowing multiple private network devices to share a public egress.

Therefore, the source address seen by the server is usually not the private IP address of the client device.

8.5 How Does a Router Forward Data?

flowchart TD
    A["Receive IP packet"] --> B["Read destination IP address"]
    B --> C["Look up routing table"]
    C --> D{"Is there a matching route?"}
    D -->|"Yes"| E["Select longest prefix match route"]
    D -->|"No"| F["Check default route"]
    F --> G{"Does a default route exist?"}
    G -->|"Yes"| H["Select default next hop"]
    G -->|"No"| I["Drop or return unreachable information"]
    E --> J["Determine next hop"]
    H --> J
    J --> K["Re-encapsulate link-layer frame"]
    K --> L["Forward packet"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style D fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style E fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style F fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style G fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style H fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style I fill:#FCE8E6,stroke:#E6A6A1,color:#7B3E3A
    style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style K fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style L fill:#DCEFE5,stroke:#8EBFA5,color:#24563F

Note that when a router forwards traffic, it usually re-encapsulates the link-layer frame, but it does not arbitrarily modify the source and destination IP addresses during ordinary routing and forwarding. Address translation devices such as NAT are an additional processing mechanism.

9. Step 8: The Server Receives and Processes the Request

After the data reaches the target network, it usually still needs to pass through a load balancer, reverse proxy, or gateway before finally being handed to the application server.

9.1 Server Request Processing Chain

Typical server-side architecture:

flowchart TD
    A["Client HTTP request"] --> B["CDN or edge node"]
    B --> C["Load balancer"]
    C --> D["Reverse proxy"]
    D --> E["API gateway"]
    E --> F["Application server"]
    F --> G["Authentication and authorization check"]
    G --> H["Business logic processing"]
    H --> I["Database or cache query"]
    I --> J["Assemble business result"]
    J --> K["Generate HTTP response"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style F fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style G fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style H fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style I fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style K fill:#DCEFE5,stroke:#8EBFA5,color:#24563F

Not every system contains all these components.

A small service may have requests handled directly by a web server; a large system may distribute requests through multiple layers of gateways and microservices.

9.2 The Role of CDN

CDN stands for Content Delivery Network.

It caches and distributes resources through edge nodes distributed across different geographic locations.

For example:

When a user visits a website, they may not access the origin server directly; instead, they access a CDN node closer to them.

Common functions of a CDN:

  • Cache static resources.
  • Reduce load on the origin server.
  • Reduce cross-region access latency.
  • Provide TLS termination.
  • Provide DDoS protection and traffic scrubbing.
  • Support some edge computing capabilities.

Note that CDN nodes may cache static resources and may also forward dynamic requests to the origin server.

9.3 Load Balancer

A load balancer distributes requests across multiple backend instances.

Common strategies:

Strategy Description
Round robin Distributes requests in sequence
Weighted round robin Distributes requests by weight
Least connections Prefers nodes with fewer connections
Consistent hashing Maps requests consistently to specific nodes
IP hashing Selects nodes based on the client address

Load balancing can improve system throughput and availability, but it also needs to be combined with health checks and failure removal mechanisms.

9.4 Reverse Proxy

A reverse proxy sits between clients and backend servers.

Common functions:

  • TLS termination.
  • Request forwarding.
  • Load balancing.
  • Path routing.
  • Static resource handling.
  • Rate limiting and access control.
  • Response compression.

For example, Nginx can forward /api/ requests to a backend service:

server {
    listen 443 ssl;
    server_name www.example.com;

    location /api/ {
        proxy_pass http://127.0.0.1:8080/;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Trusted proxy boundaries must be handled correctly; headers such as X-Forwarded-For provided by the client must not be trusted unconditionally.

9.5 Application Server Processing Business Logic

After receiving a request, the application server needs to complete:

  1. Route matching.
  2. Request parameter parsing.
  3. Authentication.
  4. Permission verification.
  5. Business logic processing.
  6. Database or cache access.
  7. Result assembly.
  8. Exception handling.

For example:

app.get("/api/users/:id", async (req, res) => {
  try {
    const userId = req.params.id;

    const user = await userService.findById(userId);

    if (!user) {
      return res.status(404).json({
        error: "User not found"
      });
    }

    res.json({
      id: user.id,
      name: user.name
    });
  } catch (error) {
    console.error(error);

    res.status(500).json({
      error: "Internal Server Error"
    });
  }
});

9.6 Database Queries

The application server may need to access the database.

For example:

SELECT id, name
FROM users
WHERE id = 1001;

Database processing time may be affected by the following factors:

  • Whether the SQL uses an index.
  • The size of the dataset.
  • Lock contention.
  • Connection pool capacity.
  • Disk I/O.
  • Cache hit rate.
  • Network latency.

Therefore, the response time of an HTTP request depends not only on the network, but also on business logic and database processing time.

Ten. Step 9: The Server Returns an HTTP Response

Once the server has finished processing, it generates an HTTP response.

10.1 The HTTP Response Message

Example of an HTTP/1.1 response:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 1256
Cache-Control: max-age=300
Date: Sat, 05 Dec 2026 12:00:00 GMT

<!DOCTYPE html>
<html>
<head>
  <title>Network</title>
</head>
<body>
  <h1>Network Request</h1>
</body>
</html>

The response mainly consists of:

  1. The status line.
  2. The response headers.
  3. A blank line.
  4. The response body.

10.2 HTTP Status Codes

Common status codes:

Status Code Meaning Description
200 OK The request succeeded
201 Created The resource was created successfully
204 No Content Successful but with no response body
301 Moved Permanently Permanent redirect
302 Found Temporary redirect
304 Not Modified Cache validation passed
400 Bad Request The request was malformed
401 Unauthorized Missing valid authentication
403 Forbidden Access denied
404 Not Found The resource does not exist
429 Too Many Requests Too many requests
500 Internal Server Error Internal server error
502 Bad Gateway The gateway received an invalid response from the upstream server
503 Service Unavailable The service is temporarily unavailable
504 Gateway Timeout The gateway timed out waiting for the upstream server

10.3 Response Headers

Common response headers:

Response Header Purpose
Content-Type Response content type
Content-Length Response body length
Content-Encoding Response content encoding
Cache-Control Caching policy
ETag Resource version identifier
Last-Modified Last modified time
Set-Cookie Set Cookie
Location Redirect target
Access-Control-Allow-Origin CORS origin permission
Content-Security-Policy Content security policy

10.4 Response Compression

To reduce the amount of data transmitted over the network, the server can compress the response content.

Common compression algorithms:

  • gzip.
  • Brotli.
  • Zstandard.

The client declares the supported encodings through a request header:

Accept-Encoding: gzip, br

The server selects a supported encoding and returns it:

Content-Encoding: br

After receiving the compressed content, the browser automatically decompresses it and then hands it over to the subsequent parsing process.

Compression can reduce transfer size, but it also adds some CPU computation overhead.

10.5 HTTP Response Sequence

sequenceDiagram
    participant C as Browser
    participant S as Server
    participant D as Database

    C->>S: Send HTTP request
    S->>S: Route matching and authentication
    S->>D: Execute data query
    D-->>S: Return query results
    S->>S: Assemble response data
    S->>C: Return status code, response headers, and response body
    C->>C: Decode and parse response content

11. Step 10: Browser Receives HTML and Parses It

After the browser receives the HTML response, it begins parsing the document.

Internally, the browser usually contains multiple collaborating modules:

  • Network module.
  • HTML parser.
  • CSS parser.
  • JavaScript engine.
  • DOM management module.
  • Style calculation module.
  • Layout module.
  • Painting module.
  • Compositing module.

11.1 HTML Parsing and DOM Construction

DOM, short for Document Object Model, is the Document Object Model.

The browser parses HTML text into a node tree.

For example:

<html>
  <body>
    <h1>Hello</h1>
    <p>Network Request</p>
  </body>
</html>

The corresponding DOM structure:

flowchart TD
    A["Document"] --> B["html"]
    B --> C["head"]
    B --> D["body"]
    D --> E["h1"]
    D --> F["p"]
    E --> G["Hello"]
    F --> H["Network Request"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style D fill:#F0EAFE,stroke:#B7A1E8,color:#334155
    style E fill:#FFF1D6,stroke:#E8C982,color:#735A20
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#F1F5F9,stroke:#CBD5E1,color:#334155
    style H fill:#F1F5F9,stroke:#CBD5E1,color:#334155