Skip to content
All writing ‹ Part 02 of 18 · A Cache Is a Chain, Not a Box
Engineering · 3 min read

One HTTP Request

An HTTP request is a function call across the network. Methods, headers, ETag, and status codes, including the HEAD and 405 that later broke a cache layer.

A request is like a function call across the network. The request carries the arguments. The response is the return value.

I am a backend engineer and I write APIs every day. But I rarely looked at the details of headers and status codes. This chase made me look at them again.

browserserver GET /assets/abc123/index.htmlHost: cdn.example.comrequest = method + path + headers 200 OKcontent-type: text/htmlcache-control: public, max-age=3600etag: "32b7140e..."(about 2 MB of HTML)response = status + headers + body
A request carries a method, a path, and headers, and the response returns a status, headers, and a body.
  • Header: one line of name: value. Every layer in the middle (CDN, load balancer) reads headers. Some layers add their own headers (Cache Headers: Who Sets, Who Reads).
  • ETag: a version label for the file content. When the content changes, the ETag changes too.

Method

  • GET: “Give me the file.” The response has headers and a body.
  • HEAD: “Give me only the headers.” The headers are the same as for GET, and the body is empty. A cache can use HEAD to check the ETag, size, and date of a file without downloading it.

Status Code

2xxsuccess200 OKThe file is here 3xxno change304 Not ModifiedYour copy is still the latest,no body 4xxrequest error404 Not FoundNothing at this path405 Method Not AllowedThe path exists, but it doesnot accept this method 5xxserver broken500, 502, 503
The first digit tells you the class, and 405 means the path exists but rejects the method.

At first I thought HEAD and 405 were obscure facts. Later, the key to the whole problem was one HEAD request that got a 405 (The Proxy Rejects HEAD, So the Refresh Always Fails).

Obscure methods and status codes are often where a bug hides.

Related: What a CDN Is, Cache Freshness: Fresh, Stale, and 304, Cache Headers: Who Sets, Who Reads, The Proxy Rejects HEAD, So the Refresh Always Fails. Or go back to the series overview.

↑↓ navigate ↵ open esc close