Skip to content

Lesson 10 of 13 · 20m

A Request Is a Contract

DNS, TLS, and the handshake behind every URL — why domain sharding died with HTTP/2, what status codes actually promise, and the headers that run caching.

Type a URL, press Enter, and in under a second a page appears. What actually happened: the URL was parsed, the hostname resolved via DNS (probably from a cache — or DNS-over-HTTPS, which changes who gets to see your lookups), a connection opened to the server, TLS negotiated, and an HTTP request went down the wire. Everything after — status codes, headers, caching — is the server's half of a contract your browser already signed.

The connection is a negotiation

Under HTTP/1.1 (RFC 2616, June 1999; rewritten as RFC 9112 in 2022), the browser opens a TCP connection, then TLS — TLS 1.3 (RFC 8446, August 2018) finishes its handshake in one round trip where TLS 1.2 took two. Then plain request bytes: a request line, headers, a blank line, a body.

Here's the part that shaped fifteen years of web ops: browsers cap at roughly six simultaneous TCP connections per host. That limit is a convention, not a spec — and the entire "domain sharding" industry, assets split across static1./static2./static3. for parallelism, existed to route around it.

HTTP/2 (RFC 9113) put multiple request streams on a single connection — multiplexing, real prioritization, header compression. No more connection cap. And it flipped domain sharding from best practice to self-sabotage overnight: extra hostnames now mean extra DNS lookups and TLS handshakes, defeating the point. If you inherit a sharded asset config, collapse it.

HTTP/3 (RFC 9114, June 2022) swapped TCP for QUIC over UDP — TLS built in, no transport-level head-of-line blocking. It already carries a large share of real traffic; the DevTools network panel shows h3 in the Protocol column when it's live.

The response is a contract too

curl -v is the ground truth — run it once:

curl -sv https://example.com -o /dev/null

You'll watch the TLS handshake, then > GET / HTTP/2, then < HTTP/2 200 plus the headers. Those headers are the contract:

  • Cache-Control — the one that matters. no-cache does not mean "don't cache"; it means "store, but revalidate every time." no-store means don't store. max-age=31536000, immutable means "never ask again" — that is what fingerprinted app.a1b2c3.js assets get.
  • ETag / If-None-Match — conditional requests. The browser sends the stored ETag; 304 Not Modified comes back with no body, saving the transfer.
  • Content-Type — the browser trusts it over the file extension, which is why a script served as text/plain never executes — and why nosniff exists.
  • Location with 301/302/307/308 — redirects. 307 and 308 preserve the method and body; a 301 historically let clients downgrade a POST to a GET.

Status codes are load-bearing

fetch does not reject on 404 or 500 — the response arrived, so the promise resolves; res.ok (status 200–299) is the check you write. A 304 means "your cache is still good." A 503 from a CDN is not your origin down — it's the edge, and Server: or CF-RAY headers tell you which.

The headers worth memorizing

  • Accept-Encoding: br, zstd — the browser's offer; Brotli and Zstandard beat gzip on text. If your server ignores it, you ship uncompressed.
  • Vary — which request headers differentiate the cached response. Vary: Accept-Encoding is mandatory; a missing Vary is how a compressed body poisons a cache entry for a client that can't read it.
  • Priority / u= — HTTP's extensible prioritization header (RFC 9218); the polite way to say "this resource matters more than that one."
  • Link: <...>; rel=preload and 103 Early Hints — pushing critical resources before the HTML finishes generating.

DNS details for the curious: A/AAAA records map names to IPs, CNAME aliases one name to another — and a CNAME can't sit at the zone apex, which is why providers invented ALIAS/ANAME flattening.

Try it yourself

// Response is a real Fetch API constructor — the same object fetch resolves with.
const res = new Response("Non-blocking is better than blocking.", {
  status: 200,
  headers: { "content-type": "text/plain" },
});
console.log(res.status, res.ok, res.headers.get("content-type"));
// A 404 resolves exactly the same way — ok:false is the only flag.

The practice

Learn curl -v, curl -I, and the DevTools network panel before any other debugging skill. Check Cache-Control before you blame a stale cache, read Server: before you blame the origin, and check res.ok before you parse.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.