How HTTP Requests Really Work: From Browser to Server

How HTTP requests work is something every developer uses daily and few ever see clearly: you type a URL, and a page appears. Between those two moments, the browser resolves a name, opens an encrypted connection, sends a structured request, and reads a structured response, all in a fraction of a second. This guide follows one request from browser to server and back, so the next time something fails, you know exactly which step to check.

Understanding the trip matters because every error you meet in web development names one of its steps. A DNS error, a TLS error, a 404, and a timeout are all different steps failing, and each one has a different fix.

Step 1: DNS Turns a Name into an Address

The browser starts with a name like example.com, but the network needs an IP address. The browser asks a DNS resolver, which walks from the root servers down to the servers that own the domain, and returns the address. That answer is cached at several levels, in the browser, the operating system, and the resolver, so repeat visits skip the lookup.

When a site fails with a DNS error, the request never left the starting line. The usual causes are a mistyped domain, a DNS record that does not exist yet, or a resolver that is down. The fix is at the DNS level, not in the application. If you run your own domain, the guide on what DNS over HTTPS is and whether you should enable it explains how the lookup itself can be encrypted, which matters on networks you do not trust.

Step 2: TCP and TLS Open a Secure Channel

With the address known, the browser opens a TCP connection to the server, usually on port 443 for HTTPS. Then the TLS handshake runs: the browser and server agree on encryption, the server presents its certificate, and the browser checks that the certificate is valid for the domain and signed by a trusted authority. Only then does any real data move.

HTTP/2 and HTTP/3 change how the connection is used, multiplexing many requests over one connection and, in the case of HTTP/3, running over QUIC instead of TCP. The details are worth knowing when you tune a server, and the guide on understanding HTTP/3 and QUIC and what changes for your server covers what the upgrade means in practice. For a small site, the practical step is simpler: get a free certificate and renew it automatically, as shown in the guide on free HTTPS with Let’s Encrypt on nginx.

How HTTP Requests Work: The Request Itself

Once the channel is open, the browser sends the request. It has four parts. The request line names the method, the path, and the HTTP version: GET /users/42 HTTP/1.1. Headers carry metadata: the host, the accepted content types, cookies, and the user agent. The body, present for POST and PUT, carries the data. And the method says what the request wants to do.

GET /users/42 HTTP/1.1
Host: example.com
Accept: application/json
Cookie: session=abc123

GET asks for data and should never change anything. POST creates, PUT replaces, PATCH updates part of a resource, DELETE removes. A GET request can be cached, bookmarked, and repeated safely. A POST cannot. That distinction is the reason browsers warn you before resubmitting a form, and it is also why an API that changes data on a GET request will eventually cause a real problem, usually when a crawler or a prefetcher calls it.

Step 4: The Server Handles It

On the server, the request usually passes through several layers before application code sees it. A reverse proxy such as nginx receives it first, terminates TLS, and forwards it to the application server. The application routes the path to a handler, the handler reads from a database or another service, and the code builds a response. Each layer can add headers, log the request, or reject it.

Most server failures happen in this step. A 500 means the application threw an error. A 502 means the proxy could not reach the application at all, which usually means the app process is down or listening on the wrong port. A 504 means the application took too long to answer. The guide on how to troubleshoot a 502 Bad Gateway on nginx walks through the proxy side, and the guide on how to diagnose high server load covers the case where the application is alive but too slow.

Step 5: The Response Trip Back

The response mirrors the request. A status line carries the code and a short message: HTTP/1.1 200 OK. Headers describe the response: content type, length, caching rules, and cookies to store. The body carries the page or the JSON. The browser reads the status first, then decides what to do with the body.

Status codes fall into five groups. 2xx means success. 3xx means redirect, follow the Location header. 4xx means the client did something wrong: 400 for a bad request, 401 for missing auth, 403 for forbidden, 404 for not found. 5xx means the server failed. When debugging, read the code before the body: it tells you which side owns the problem.

Caching headers decide whether the browser stores the response and reuses it. A response with a long max-age is served from cache without a network trip. A response with no-store is fetched fresh every time. Misconfigured caching is a common source of “the fix is deployed but I still see the old page,” and the fix is usually a header, not a redeploy.

What to Check When a Request Fails

Work through the steps in order. Can the name resolve? Open a terminal and check DNS. Can the connection open? Try the address and port directly. Does TLS work? Check the certificate dates and the chain. Does the server answer? Read the status code. Is the response what you expected? Inspect the headers and the body.

Browser developer tools show all of this in the Network tab: the request, the response, the timing of each phase, and the size of each part. That tab is the single most useful debugging tool for anything over HTTP, and it answers most questions about a slow or failing request in seconds. Learn to read it, and the whole trip from browser to server stops being a mystery.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.