Reference

HTTP & network inspection

Decode requests, responses, browser rules and network diagnostics.

Scope and conventions

Wire examples use HTTP/1.1 notation; HTTP/2 and HTTP/3 encode it differently. Commands use a Unix-like shell and illustrative example.test hosts. Browser security behavior is labeled separately from HTTP and command-line clients.

Caching & retries

Choose freshness and storage rules

HTTP & tools

max-age sets freshness lifetime in seconds. no-cache allows storage but requires validation before reuse. no-store forbids storage. private excludes shared-cache storage.

Fragment

HTTP & tools · Choose freshness and storage rules
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
Cache-Control: private, no-cache

Freshness is not a permission check. Avoid storing personalized responses in shared caches unless deliberately designed.

Include the right request headers in a cache key

HTTP & tools

Vary names request headers that select the representation. A cache must distinguish their values when deciding reuse.

Fragment

HTTP & tools · Include the right request headers in a cache key
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
Vary: Accept-Encoding, Origin

Vary is not a replacement for selecting an appropriate private/no-store policy.

Revalidate and update with validators

HTTP & tools

A validator identifies one version of a representation. The server sends ETag (an opaque tag) and/or Last-Modified (a date). On the next GET the client returns them as If-None-Match or If-Modified-Since. If nothing changed, the server answers 304 Not Modified with no body, and the client reuses its stored copy. For writes, If-Match: "tag" makes a PUT, PATCH or DELETE apply only if the resource is still at that version; otherwise the server answers 412 Precondition Failed and the client re-reads before retrying. If-None-Match: * on a PUT means create only if absent. In practice: prefer ETag over Last-Modified, which has one-second resolution. Use If-Match for any read-modify-write, so concurrent editors cannot silently overwrite each other.

Fragment

HTTP & tools · Revalidate and update with validators
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
# 1. First read
GET /items/42 HTTP/1.1
Host: api.example.test

HTTP/1.1 200 OK
ETag: "rev-7"
Last-Modified: Thu, 01 Oct 2026 09:00:00 GMT
Cache-Control: no-cache
Content-Type: application/json

{"id":42,"qty":2}

# 2. Revalidate: unchanged
GET /items/42 HTTP/1.1
Host: api.example.test
If-None-Match: "rev-7"

HTTP/1.1 304 Not Modified
ETag: "rev-7"
Cache-Control: no-cache

# 3. Update only if still rev-7; someone else changed it first
PUT /items/42 HTTP/1.1
Host: api.example.test
If-Match: "rev-7"
Content-Type: application/json

{"id":42,"qty":3}

HTTP/1.1 412 Precondition Failed

# curl: store the ETag, then send it back as If-None-Match
curl -sS --etag-save etag.txt -o item.json https://api.example.test/items/42
curl -sS --etag-compare etag.txt -o item.json -w '%{http_code}\n' \
  https://api.example.test/items/42
# If-Modified-Since from a date (or from a file's mtime with -z FILE)
curl -sS -z 'Thu, 01 Oct 2026 09:00:00 GMT' -o item.json \
  https://api.example.test/items/42

If-None-Match uses weak comparison, so W/"..." tags still produce 304. If-Match uses strong comparison and never matches a weak tag. Servers that compress on the fly often weaken their ETags.

When a request has both, If-None-Match takes precedence and If-Modified-Since is ignored.

A 304 must repeat headers the 200 would have carried, such as ETag, Cache-Control, Expires and Vary. A server can reply 428 Precondition Required (RFC 6585) to demand If-Match on updates.

--etag-save and --etag-compare need curl 7.68+.

Make retried writes safe with idempotency keys

HTTP & tools

A method is idempotent when sending the same request several times has the same intended effect as sending it once. RFC 9110 defines GET, HEAD, OPTIONS and TRACE (the safe methods) plus PUT and DELETE as idempotent, so a client may retry them after a lost response. POST and PATCH are not idempotent, and blindly retrying a POST can create a second order or a second charge. The Idempotency-Key request header gives a POST a client-chosen unique key. The server stores the key with a fingerprint of the request and the first response. A repeat with the same key replays the stored response instead of acting again. Status: it is an IETF HTTPAPI working-group Internet-Draft (draft-ietf-httpapi-idempotency-key-header-08, October 2026), not an RFC. Payment and commerce APIs widely use the same pattern. In practice: generate one random key (a UUID) per logical operation, reuse it for every retry of that operation, and never reuse it for a different payload.

Fragment

HTTP & tools · Make retried writes safe with idempotency keys
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
POST /payments HTTP/1.1
Host: api.example.test
Content-Type: application/json
Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"

{"amount":1250,"currency":"EUR"}

HTTP/1.1 201 Created
Location: /payments/981

# Retry after a timeout, same key and same body:
# the server returns the stored 201 for /payments/981, without charging again.

# Same key while the first request is still running  -> 409 Conflict
# Same key with a different body                     -> 422 Unprocessable Content
# Key missing where the API requires one             -> 400 Bad Request

key=$(uuidgen)
curl -sS --retry 3 -X POST https://api.example.test/payments \
  -H 'Content-Type: application/json' \
  -H "Idempotency-Key: \"$key\"" \
  -d '{"amount":1250,"currency":"EUR"}'

Idempotent is about the effect on the server, not the response: a repeated DELETE may return 404 the second time and still be idempotent.

The draft defines the value as a Structured Field string, so it is quoted. Many existing APIs predate the draft and accept a bare token; follow the API’s own documentation.

The server must store keys atomically, apply a documented expiry window, and decide whether failed responses are replayed. Without that storage the header does nothing.

curl --retry resends the same body with the same header line, so a retried POST is only safe if the server honours the key.

Back off with jitter before retrying

HTTP & tools

Retry only failures that may succeed later: connection errors, timeouts, 408, 429, 502, 503 and 504, and 500 when the operation is idempotent. Other 4xx responses repeat the same mistake. Exponential backoff doubles the wait after each attempt, up to a cap. Jitter randomizes each wait so that many clients that failed together do not retry together. A common form, full jitter, sleeps a random time between 0 and the current ceiling. When a 429 or 503 carries Retry-After (seconds or an HTTP date), wait at least that long. Bound the whole operation by a maximum number of attempts and a deadline. curl --retry N implements exponential backoff without jitter. It waits 1 s, doubles each time up to 10 minutes, and follows Retry-After since 7.66.0. In practice: retry only idempotent requests or ones carrying an idempotency key, and add jitter yourself when many clients run the same job.

Fragment

HTTP & tools · Back off with jitter before retrying
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
HTTP/1.1 503 Service Unavailable
Retry-After: 30

HTTP/1.1 429 Too Many Requests
Retry-After: Thu, 01 Oct 2026 09:05:00 GMT

# curl built-in: 5 retries, 1 s doubling backoff, no retry starts after 60 s,
# each attempt limited to 10 s, and a refused connection also retried
curl -sS --retry 5 --retry-max-time 60 --max-time 10 \
  --retry-connrefused https://api.example.test/items

# Fixed delay instead of backoff
curl -sS --retry 5 --retry-delay 2 https://api.example.test/items

# Exponential backoff with full jitter in a shell loop
url=https://api.example.test/items
max_attempts=5 base=1 cap=30
for attempt in $(seq 1 "$max_attempts"); do
  status=$(curl -sS -o body.json -w '%{http_code}' --max-time 10 "$url")
  case $status in
    2??) break ;;
    000|408|429|500|502|503|504) ;;   # 000: no HTTP response
    *) echo "HTTP $status: not retryable" >&2; exit 1 ;;
  esac
  [ "$attempt" -eq "$max_attempts" ] && { echo "giving up" >&2; exit 1; }
  ceiling=$(( base * 2 ** (attempt - 1) ))
  [ "$ceiling" -gt "$cap" ] && ceiling=$cap
  sleep $(( RANDOM % (ceiling + 1) ))   # random 0..ceiling seconds
done

curl treats a timeout, HTTP 408, 429, 500, 502, 503, 504, 522 and 524 (and FTP 4xx) as transient. A refused connection counts only with --retry-connrefused (7.52.0+).

--retry-delay replaces the exponential backoff with a fixed wait. --retry-max-time caps the time allowed for retries, but a single attempt can still run past it unless -m/--max-time is set.

--retry-all-errors (7.71.0+) retries every failure. The manual warns that it can send or receive duplicate data and should not be a default.

The shell loop uses bash’s RANDOM, which is not suitable for anything security-related and is fine for jitter. It does not parse Retry-After; honour it in real clients.