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.

  1. Browser
  2. Web server
  1. Request: GET /index.htmlBrowser to Web server
  2. Response: 200 OKWeb server to Browser
  3. Later: "Has it changed?"Browser to Web server
  4. 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: */*

FieldTextWhat it means
Request lineGET /index.html HTTP/1.1The method (GET: please send), the path of the page and the protocol version.
Host headerHost: example.comWhich website you want. One server can host many sites, so this is required.
User-Agent headerUser-Agent: curl/8.5.0Names the program making the request.
Accept headerAccept: */*Which formats the client can read. */* means "anything".
Blank lineAn 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!
FieldTextWhat it means
Status lineHTTP/1.1 200 OKThe version, a status code (200 means success) and a short reason.
Content-Type headerContent-Type: text/htmlTells the browser how to treat the body: as a web page.
Content-Length headerContent-Length: 13The body is exactly 13 bytes, so the browser knows where it ends.
ETag headerETag: "abc123"A label for this version of the page. The browser can ask later: "has it changed?"
Blank lineEnds the headers. The body follows.
BodyHello, 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"

FieldTextWhat it means
Request lineGET /index.html HTTP/1.1The same request as before.
Host headerHost: example.comThe same site.
If-None-Match headerIf-None-Match: "abc123"The browser says: "I already have version abc123. Only send the page if it has changed."
Blank lineEnds 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"

FieldTextWhat it means
Status lineHTTP/1.1 304 Not Modified304 means "your copy is still good".
ETag headerETag: "abc123"Confirms the version.
Blank lineThere 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.

Back to Network Lab

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.