Skip to content
BENIBIX Learn

HTTP Requests and Responses

Level 4 · HTTP, the language of the web

What HTTP is and what a request and a response look like line by line. What headers carry, and how to see them yourself with curl.

Course contentsLesson 9 of 13

After this lesson you can

  • Read the first line of a request and a response
  • Say what headers are for
  • Look at real headers with curl

12 mincovers 4 glossary entries

Worth reading first: DNS and Domain Names, Network Ports, 80 and 443

What a browser sends, and what comes back

HTTP is the set of rules a browser uses to ask a server for a page. The browser sends a request, and the server sends back a response. Every web page, image and click on a website is one or more of these pairs. It is plain text, so you can read it.

A request starts with one line. First comes the method, such as GET, which says what to do. Then the path, such as /menu, which says which thing. Then the version of HTTP. So GET /menu HTTP/1.1 asks for the menu page.

Headers come next, one per line, each a name and a value. Host names the site, because one server can hold many sites. Accept says what kind of reply the browser can read. Other headers carry cookies, the language you prefer and which browser you use.

After the headers comes a blank line, then the body, if there is one. A plain page request has no body. A form you submit sends its fields in the body. The blank line is how the server knows the headers have ended.

The response has the same shape. Its first line holds the version and a three-digit code, such as 200, which means it worked. Then come headers about the reply, such as its size and how long it may be kept. Then the body: the page, the image or the data.

Each pair stands alone. The server does not remember your last request by itself. That is why sites use cookies: a small value the server hands over once, which the browser sends back in a header every time after.

A common mistake is to look only at the page and never at the headers. When a site acts strangely, the headers often explain it. The curl command with -I shows them for any address, in a second.

console
$ curl -I https://emmas-shop.com/menu
HTTP/2 200
content-length: 5120
cache-control: max-age=60
The -I asks only for the headers. The first line says the version and the code, 200 for success.
A request and a response share one shape: a first line, headers, a blank line, and a body.

Worked example

A bakery's page will not update

Lucy changes the prices on her bakery's site, but customers still see the old ones. She runs curl -I on the page.

The response says the page may be kept for 86,400 seconds, a whole day. She sets it to 60 seconds, and the new prices show up within a minute.

The words for this lesson4

Check yourself

What are HTTP headers for?

Finished this lesson?

Marking it complete also marks its 4 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.