HTTP is just text on a connection

A web request is a few lines of plain text sent over an open connection, and the answer is a few more lines. Once you can read them, the output of `curl -v` is easy to follow. The versions of HTTP change how many requests share one connection.

Part 4 of 9 · Networking3 min read
requestGET / HTTP/1.1Host: example.comAccept: */*responseHTTP/1.1 200 OKContent-Type: text/html<html> ... </html>both sides are plain textfirst line, notes, empty line, contentone connectionreused for the next request1.12 / 3curl -v http://example.comevery line, both ways> we send, < we receivehow many fit at onceHTTP/1.1, 2 and 3 differ here

In part 3 the connection is open. Inside it travel lines of text, for a web page, an API call or a payment. We can type a request by hand, and the server answers in the same plain way.

In the post office picture, the open connection is the registered envelope, and HTTP is the letter inside. HTTP says what the letter looks like: a first line with the request, a few lines of notes, and then the content.

A request is a few lines

Send a request without a browser. Port 80 is the default port for plain HTTP, and printf writes the lines for us:

Shell
docker run --rm alpine sh -c 'apk add -q netcat-openbsd &&
printf "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n" | 
nc example.com 80  | head -6' 
HTTP/1.1 200 OK
Date: Sun, 18 Oct 2026 17:48:13 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Server: cloudflare

Here is what each marked part does:

  1. 1printf "GET / HTTP/1.1\r\n..." writes the request. \r\n is the line break that HTTP uses.
  2. 2| nc example.com 80 sends the text to port 80 and prints the answer.
  3. 3head -6 keeps the first six lines.

We sent three lines and an empty line. The first line has three parts: the method GET (give me this), the path /, and the version. Host names the site, because one machine can serve many names. Connection: close asks the server to close the connection after the answer. The empty line ends the notes, which are called headers. The server answered with a status line, 200 OK. Here 200 is the status code. The server then sent its own headers and the content. We cut them off with head.

requestGET / HTTP/1.1Host: example.comAccept: */*responseHTTP/1.1 200 OKContent-Type: text/htmlServer: cloudflare<html> ... </html>first lineheadersempty linecontent
A request and a response are both lines of text: a first line, notes, an empty line, and then the content.

curl shows both sides

curl -v prints each line it sends with a > and each line it receives with a <:

Shell
docker run --rm alpine sh -c 'apk add -q curl &&
curl -sv  http://example.com -o /dev/null  2>&1 | grep -E "^[<>]"  | head -11'
> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/8.22.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Sun, 18 Oct 2026 17:48:13 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Server: cloudflare

Here is what each marked part does:

  1. 1curl -sv URL prints the request and the answer. The option -s hides the progress meter, and -v shows the lines.
  2. 2-o /dev/null throws the page away. 2>&1 joins the messages into the output so that grep can read them.
  3. 3grep -E "^[<>]" keeps the lines that start with < or >.

This is our request again, with two notes that curl added: who is asking (User-Agent) and what it accepts (Accept). The answer differs in one place: Connection: keep-alive. The server offers to keep the connection open, and the next section uses that. If a proxy adds a header or a server sends a wrong Content-Type, the line appears in this output.

One connection, many requests

Opening a connection takes three packets, and the padlock in part 5 adds more. A client therefore reuses a connection for the next request. Ask for the same page twice in one curl command:

Shell
docker run --rm alpine sh -c 'apk add -q curl &&
curl -sv http://example.com http://example.com -o /dev/null  -o /dev/null 2>&1 |
grep -E "^\* (Established|Reusing)"' 
* Established connection to example.com (104.20.23.154 port 80) from 172.17.0.2 port 53340 
* Reusing existing http: connection with host example.com

Here is what each marked part does:

  1. 1Two URLs in one curl command make two requests. The two -o /dev/null options throw both pages away.
  2. 2grep -E "^\* (Established|Reusing)" keeps the connection messages that curl prints.

The connection opened once, and the second request used it. On one HTTP/1.1 connection, the requests go one after another. If the first answer is slow, the second waits behind it. For this reason a browser often opens several connections to the same server.

The versions change how many fit at once

The newer versions of HTTP keep the same methods, paths, notes and status codes. They change how the lines travel. HTTP/2 sends many requests at the same time over one connection, each as a numbered stream, so a slow answer does not block the others. HTTP/3 keeps this idea but runs over UDP instead of TCP, so one lost packet stops fewer streams. The client and the server agree on the version while they open the connection. We can ask for each version:

Shell
docker run --rm alpine sh -c 'apk add -q curl &&
curl -s --http1.1 -o /dev/null -w "%{http_version}\n" https://example.com &&  
curl -s --http2 -o /dev/null -w "%{http_version}\n" https://example.com'
1.1
2

Here is what each marked part does:

  1. 1--http1.1 and --http2 choose the version.
  2. 2-w "%{http_version}\n" prints the version that was really used.

The same server answered both. In HTTP/2 the status line reads HTTP/2 200 instead of HTTP/1.1 200 OK. The notes and the status mean the same, but they travel in a compact binary form. The server also sends a header named alt-svc: h3=":443", which tells clients that HTTP/3 is available on port 443.

HTTP/1.1123one after anotherslow: the rest waitHTTP/2123many at onceHTTP/3123many at onceover UDP, not TCP
HTTP/1.1 serves one request after another on a connection. HTTP/2 and HTTP/3 let several requests share one connection at the same time.

Key points

  • An HTTP request is a first line, a few notes called headers, an empty line, and then the content.
  • The server answers with a status line, headers, an empty line and the content.
  • curl -v shows each line: > for what we send and < for what we receive.
  • A client reuses one connection for several requests, because opening a connection takes time.
  • HTTP/1.1, HTTP/2 and HTTP/3 use the same methods and status codes. They differ in how many requests share one connection.

Next, in part 5: what the padlock in the address bar proves, and what it does not.

New posts by email

One email when a post ships, about twice a month. Nothing else, and one click to leave.

Latest: Finding where a request breaks · RSS