HTTP and HTTPS

Know the request/response model, methods, status codes and headers that every web service, load balancer and health check speaks.

Beginner · about 5 hours · difficulty 2/5

Learn first: DNS in Practice

HTTP is the language of almost every service you will operate. Health checks, API gateways, CDNs, load balancers and ingress controllers all make decisions based on HTTP details.

Fundamentals

  • Request: method (GET, POST, PUT, PATCH, DELETE), path, headers, optional body.
  • Response: status code, headers, body.
  • Status codes: 2xx success, 3xx redirects (301 vs 302), 4xx client errors (400, 401, 403, 404, 429), 5xx server errors (500, 502 bad gateway, 503 unavailable, 504 gateway timeout). For ops, 502 and 504 usually mean "the proxy could not get a good answer from the upstream".
  • Headers you will touch: Host, Content-Type, Authorization, Cache-Control, X-Forwarded-For, X-Request-ID.

Versions

HTTP/1.1 (keep-alive), HTTP/2 (multiplexing over one connection) and HTTP/3 over QUIC/UDP. HTTPS is HTTP inside TLS.

Operational topics

Caching and CDNs, cookies and sessions (sticky sessions), CORS, compression, timeouts and retries (only retry idempotent requests), and rate limiting.

Tools

curl -v, curl -I, curl -w '%{time_total}', browser dev tools, and httpie.

Good enough to move on: you can read a raw request and response, explain what a 502 versus a 504 means at a proxy, and time each phase of a request with curl.

Key concepts

  • Methods and idempotency
  • Status codes
  • Headers and X-Forwarded-*
  • HTTP/1.1, HTTP/2, HTTP/3
  • Caching and CDNs
  • CORS and cookies
  • curl for debugging

Mini project

Write a curl-based script that reports DNS time, connect time, TLS time and time to first byte for a list of URLs, and run it against a site behind a CDN and one without.

Check yourself

Why is it safe for a load balancer to retry a failed GET but risky to retry a POST?

Free resources