The Protocol of the Web
"HTTP is the foundation of all data communication on the World Wide Web. Every time you load a page, submit a form, or call an API, HTTP is the protocol carrying your request."
CSE 135 — Full Overview | Review Questions
An application-layer, client-server, stateless, request-response protocol.
Same semantics, better performance — from one-request-per-connection to multiplexed streams.
| Version | Year | Key Features | Connection Model |
|---|---|---|---|
| HTTP/0.9 | 1991 | GET only, no headers, HTML only | One request per connection |
| HTTP/1.0 | 1996 | Headers, status codes, POST, Content-Type | One request per connection |
| HTTP/1.1 | 1997 | Persistent connections, chunked transfer, Host header | Keep-alive (reuse connections) |
| HTTP/2 | 2015 | Binary framing, multiplexing, HPACK compression | Single connection, multiplexed streams |
| HTTP/3 | 2022 | QUIC transport (UDP), no head-of-line blocking | QUIC with multiplexed streams |
Every HTTP interaction: client sends a request, server sends a response. Both follow the "Law of Three."
| Part | Request | Response |
|---|---|---|
| 1. Start line | Request line: GET /page HTTP/1.1 | Status line: HTTP/1.1 200 OK |
| 2. Headers | Host, Accept, User-Agent, etc. | Content-Type, Content-Length, etc. |
| 3. Body | Optional (POST, PUT, PATCH) | Optional (HTML, JSON, image, etc.) |
Steps 2 and 3 (TCP + TLS) only happen for the first request. Subsequent requests reuse the connection.
Request line + headers + blank line + optional body.
METHOD /path HTTP/version — exactly three parts:
/api/books)HTTP/1.1Status line + headers + blank line + optional body. Same three-part structure as requests.
Content-Type header tells the client how to interpret the body.
Verbs that indicate the desired action: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS.
| Method | Purpose | Body? | Safe? | Idempotent? |
|---|---|---|---|---|
| GET | Retrieve a resource | No | Yes | Yes |
| POST | Submit data / create | Yes | No | No |
| PUT | Replace entirely | Yes | No | Yes |
| PATCH | Partial modify | Yes | No | No |
| DELETE | Remove a resource | Optional | No | Yes |
| HEAD | GET without body | No | Yes | Yes |
| OPTIONS | Communication options | Optional | Yes | Yes |
Two properties that define how methods behave — and determine what's safe to cache, retry, and prefetch.
GET /api/users/5/delete — browsers, crawlers, and prefetch mechanisms will call it freely. Google's crawler once deleted data from an app that did this.
Three-digit numbers: 1xx info, 2xx success, 3xx redirect, 4xx client error, 5xx server error.
| Category | Range | Meaning |
|---|---|---|
| 1xx | 100–199 | Informational — processing continues |
| 2xx | 200–299 | Success — request accepted |
| 3xx | 300–399 | Redirection — further action needed |
| 4xx | 400–499 | Client Error — your fault |
| 5xx | 500–599 | Server Error — server's fault |
| Code | Name | Key Detail |
|---|---|---|
200 | OK | The most common status code |
201 | Created | New resource; include Location header |
204 | No Content | Success, no body (common for DELETE) |
301 | Moved Permanently | New permanent URL; may change POST to GET |
304 | Not Modified | Use cached version (no body) |
307 | Temporary Redirect | Preserves method (POST stays POST) |
| Code | Name | Key Detail |
|---|---|---|
400 | Bad Request | Malformed syntax or invalid input |
401 | Unauthorized | Not authenticated (should be "Unauthenticated") |
403 | Forbidden | Authenticated but not authorized |
404 | Not Found | Resource doesn't exist |
405 | Method Not Allowed | Wrong HTTP method for this URL |
409 | Conflict | Conflicts with current resource state |
422 | Unprocessable Entity | Valid syntax but invalid semantics |
429 | Too Many Requests | Rate limited; check Retry-After |
| Code | Name | Key Detail |
|---|---|---|
500 | Internal Server Error | Generic server-side failure |
502 | Bad Gateway | Invalid response from upstream |
503 | Service Unavailable | Overloaded or maintenance |
504 | Gateway Timeout | Upstream didn't respond in time |
Metadata about the request or response: Name: value pairs, case-insensitive.
| Header | Purpose | Example |
|---|---|---|
Host | Which domain (required in HTTP/1.1) | Host: example.com |
Accept | Preferred content types | Accept: application/json |
User-Agent | Identifies the client | Mozilla/5.0 ... |
Authorization | Credentials | Bearer eyJhbG... |
Cookie | Stored cookies sent back | session_id=abc123 |
Accept-Encoding | Compression support | gzip, deflate, br |
| Header | Purpose | Example |
|---|---|---|
Content-Type | Body format | application/json; charset=utf-8 |
Content-Length | Body size in bytes | 348 |
Location | Redirect or new resource URL | /api/books/42 |
Set-Cookie | Sets a cookie on the client | session=abc; HttpOnly |
Cache-Control | Caching directives | max-age=3600 |
Server | Server software | nginx/1.24 |
Referrer-Policy header uses the correct spelling, making the inconsistency permanent.
Client and server agree on the best format using Accept headers and quality values.
| Header | Negotiates | Example |
|---|---|---|
Accept | Content type | text/html, application/json;q=0.9 |
Accept-Language | Language | en-US, fr;q=0.5 |
Accept-Encoding | Compression | gzip, br |
Vary: Accept, a cache might serve a JSON response to a client that wants HTML.
Two ways: in the URL (query strings) or in the request body (form-encoded, multipart, JSON).
| Format | Content-Type | Files? | Nesting? | Use Case |
|---|---|---|---|---|
| Query string | N/A (in URL) | No | No | GET filtering, search, pagination |
| Form-encoded | application/x-www-form-urlencoded | No | No | HTML form submissions |
| Multipart | multipart/form-data | Yes | Limited | File uploads |
| JSON | application/json | No | Yes | APIs, fetch() calls |
Store response copies to reuse without contacting the server. Reduces latency and server load.
| Directive | Meaning |
|---|---|
public | Any cache (browser, CDN, proxy) can store it |
private | Only the browser can cache it (user-specific data) |
no-cache | Cache it, but revalidate before using |
no-store | Do not cache at all (sensitive data) |
max-age=N | Fresh for N seconds |
immutable | Never changes (versioned assets like app.v3.js) |
no-store.
HTTP is stateless. Cookies bolt state onto a stateless protocol via Set-Cookie / Cookie headers.
| Attribute | Purpose |
|---|---|
HttpOnly | Not accessible via JavaScript (blocks XSS) |
Secure | Only sent over HTTPS |
SameSite | Controls cross-site sending (Strict, Lax, None) |
Max-Age | Seconds until expiration |
Domain | Which domain(s) receive the cookie |
| Approach | State Stored | Best For |
|---|---|---|
| Server sessions | On the server (cookie holds session ID) | Traditional web apps |
| Tokens (JWT) | In the token itself (stateless) | APIs, SPAs, mobile apps |
HttpOnly, Secure, and SameSite=Lax (or Strict) on session cookies.
Cross-Origin Resource Sharing — how servers opt in to allowing requests from different origins.
Two URLs share the same origin only if scheme + host + port all match:
| URL A | URL B | Same? | Why |
|---|---|---|---|
https://app.com/a | https://app.com/b | Yes | Same scheme, host, port |
https://app.com | http://app.com | No | Different scheme |
https://app.com | https://api.app.com | No | Different host (subdomain) |
https://app.com | https://app.com:8080 | No | Different port |
Challenge-response framework: 401 + WWW-Authenticate → client sends credentials.
| Method | How It Works | Pros | Cons |
|---|---|---|---|
| Basic Auth | Base64 user:pass in every request | Simple, universal | Encoding, not encryption |
| Bearer / JWT | Token in Authorization header | Stateless, scalable | Token management |
| API Key | Key in header or query | Easy to provision/revoke | No standard; visible in logs if in URL |
| Cookie Session | Session ID in cookie | Browser handles it, HttpOnly | Server-side state, CSRF risk |
dXNlcjpwYXNzd29yZA== decodes to user:password. Anyone who intercepts the request can read credentials. Never use Basic Auth without HTTPS.
| Aspect | Cookie Sessions | Token-Based (JWT) |
|---|---|---|
| State | Server stores session data | Token contains all data |
| Sent how | Automatically (Cookie header) | Manually (Authorization header) |
| Cross-domain | Complex (CORS + SameSite) | Easy (just include header) |
| Revocation | Easy (delete server session) | Hard (valid until expiry) |
| Best for | Traditional web apps | APIs, SPAs, mobile, microservices |
Response headers that instruct browsers to enable additional security protections.
| Header | Purpose | Example |
|---|---|---|
Strict-Transport-Security | Forces HTTPS | max-age=31536000; includeSubDomains |
Content-Security-Policy | Controls resource loading | default-src 'self' |
X-Content-Type-Options | Prevents MIME sniffing | nosniff |
X-Frame-Options | Blocks clickjacking | DENY |
Referrer-Policy | Controls Referer header | strict-origin-when-cross-origin |
Permissions-Policy | Controls browser features | camera=(), microphone=() |
HTTP + TLS = encryption, integrity, and authentication. Three guarantees for secure communication.
DevTools Network tab for browsers, curl -v for the command line.
| Flag | Purpose |
|---|---|
-v | Verbose — show full headers |
-i | Include response headers |
-I | HEAD request (headers only) |
-H | Add custom header |
-d | Send body data (implies POST) |
-X | Specify HTTP method |
-L | Follow redirects |
18 sections of HTTP fundamentals in one table.
| Concept | Key Points |
|---|---|
| What is HTTP | Application-layer, client-server, stateless, request-response |
| Versions | 0.9 → 1.0 → 1.1 (keep-alive) → 2 (multiplexing) → 3 (QUIC) |
| Request-Response | Three parts each: start line, headers, body |
| Methods | GET (read), POST (create), PUT (replace), PATCH (update), DELETE (remove) |
| Safety/Idempotency | Safe = no side effects. Idempotent = repeatable. POST is neither. |
| Status Codes | 1xx info, 2xx success, 3xx redirect, 4xx client, 5xx server |
| Headers | Request, response, representation, general. Host is required. |
| Content Negotiation | Accept headers + quality values. Vary header for caching. |
| Sending Data | Query strings (GET), form-encoded, multipart (files), JSON (APIs) |
| Caching | Cache-Control, ETag, 304 Not Modified. no-cache ≠ don't cache. |
| Cookies | Set-Cookie/Cookie for state. HttpOnly + Secure + SameSite. |
| CORS | Same-Origin Policy. CORS headers let servers opt in to cross-origin. |
| Authentication | Basic (encoding), Bearer/JWT (stateless), API keys, cookie sessions |
| Security Headers | HSTS, CSP, X-Content-Type-Options, X-Frame-Options |
| HTTPS/TLS | Encryption + integrity + authentication. HTTPS ≠ safe site. |
| Observing HTTP | DevTools Network tab + curl -v. "Copy as curl" bridges both. |