Web and appsApplicationRFC 9110 and RFC 9112
HTTP: how the web asks and answers
The plain-text request and reply behind every web page, image and API call.
Ports and use: TCP 80 (HTTPS uses 443)
In one sentenceA browser sends a request line and headers; the server answers with a status code, headers and the content.
Think of it like thisIt is ordering at a counter: you say what you want, and the server hands back the item or tells you why not.
Watch it happen
4 steps and 4 byte-by-byte decodes. Use the buttons or the arrow keys. Hover or focus a field to find its bytes.
- Browser
- Web server
- Request: GET /index.htmlBrowser to Web server
- Response: 200 OKWeb server to Browser
- Later: "Has it changed?"Browser to Web server
- 304 Not ModifiedWeb server to Browser
Step 1 of 4 Request: GET /index.html
Browser → Web server
After the TCP connection opens, the browser sends this text. Each line ends with a carriage return and line feed, shown here as the symbol that ends each line.
HTTP request 84 bytes
GET /index.html HTTP/1.1↵ Host: example.com↵ User-Agent: curl/8.5.0↵ Accept: */*↵ ↵
| Field | Text | What it means |
|---|---|---|
| Request line | GET /index.html HTTP/1.1↵ | The method (GET: please send), the path of the page and the protocol version. |
| Host header | Host: example.com↵ | Which website you want. One server can host many sites, so this is required. |
| User-Agent header | User-Agent: curl/8.5.0↵ | Names the program making the request. |
| Accept header | Accept: */*↵ | Which formats the client can read. */* means "anything". |
| Blank line | ↵ | An empty line ends the headers. A GET has no body. |
Step 2 of 4 Response: 200 OK
Web server → Browser
The server finds the page and replies with the status, headers and the content.
HTTP response 93 bytes
HTTP/1.1 200 OK↵ Content-Type: text/html↵ Content-Length: 13↵ ETag: "abc123"↵ ↵ Hello, world!
| Field | Text | What it means |
|---|---|---|
| Status line | HTTP/1.1 200 OK↵ | The version, a status code (200 means success) and a short reason. |
| Content-Type header | Content-Type: text/html↵ | Tells the browser how to treat the body: as a web page. |
| Content-Length header | Content-Length: 13↵ | The body is exactly 13 bytes, so the browser knows where it ends. |
| ETag header | ETag: "abc123"↵ | A label for this version of the page. The browser can ask later: "has it changed?" |
| Blank line | ↵ | Ends the headers. The body follows. |
| Body | Hello, world! | The 13 bytes of the page. |
Step 3 of 4 Later: "Has it changed?"
Browser → Web server
Next visit, the browser asks again but sends the version label it saved.
Conditional request 72 bytes
GET /index.html HTTP/1.1↵ Host: example.com↵ If-None-Match: "abc123"↵ ↵
| Field | Text | What it means |
|---|---|---|
| Request line | GET /index.html HTTP/1.1↵ | The same request as before. |
| Host header | Host: example.com↵ | The same site. |
| If-None-Match header | If-None-Match: "abc123"↵ | The browser says: "I already have version abc123. Only send the page if it has changed." |
| Blank line | ↵ | Ends the headers. |
Step 4 of 4 304 Not Modified
Web server → Browser
The page has not changed, so the server sends only headers. The browser reuses its saved copy.
Short reply 45 bytes
HTTP/1.1 304 Not Modified↵ ETag: "abc123"↵ ↵
| Field | Text | What it means |
|---|---|---|
| Status line | HTTP/1.1 304 Not Modified↵ | 304 means "your copy is still good". |
| ETag header | ETag: "abc123"↵ | Confirms the version. |
| Blank line | ↵ | There is no body, which saves bandwidth and time. |
Where you meet it
- Loading web pages, images, scripts and fonts.
- Every REST API call between an app and its server.
- Webhooks, where one service calls another with a request.
Common mistakes
- Mixing up 4xx errors (the request was wrong) and 5xx errors (the server failed).
- Forgetting that plain HTTP is readable by anyone on the path. Use HTTPS.
- Sending secrets in the URL, which ends up in logs and browser history.
- Disabling caching headers and then wondering why the site is slow.
Try it yourself
Run these on your own computer and compare the output with the lesson above.
curl -v http://example.com/Shows the request and response headers.curl -I https://example.com/Asks for the headers only.curl -H "If-None-Match: \"abc123\"" -I https://example.com/Try a conditional request on a site that sends ETags.
Addresses and values in the examples are made up for teaching (the 203.0.113.x range is reserved for documentation). Real traffic carries more options and details. Check the standard named above for the full rules.