Skip to content
Sign inGet all access
Chapter 1·8 minFree

What HTTP Is

A text protocol over a socket, and the three tools to read it.

HTTP is text you can type. Everything in this course is bytes on a socket.

Request and response

One side asks, the other answers:

curl -sI localhost:8080 | head -5
OutputHTTP/1.1 200 OKServer: nginx/1.27.5Date: <now>Content-Type: text/htmlContent-Length: 615

No handshake you write, no session, no “connect”. One request, one response.

Where HTTP sits

TCP carries the bytes. HTTP decides what they mean:

GET / HTTP/1.1
Host: localhost
Connection: close
OutputHTTP/1.1 200 OKServer: nginx/1.27.5

Chapter 2 sends that by hand. The shell for it is one printf piped into nc:

terminal
printf '%s\r\n' \
  'GET / HTTP/1.1' \
  'Host: localhost' \
  'Connection: close' \
  '' | nc localhost 8080 | head -2
OutputHTTP/1.1 200 OKServer: nginx/1.27.5

A server to practise against

One command gives you a server that answers honestly and never rate-limits:

terminal
docker run -d --name web \
  -p 8080:80 nginx:1.27-alpine
Output$ docker run -d --name web -p 8080:80 nginx:1.27-alpine$ curl -s -o /dev/null -w '%{http_code}' localhost:8080200

Every chapter until TLS talks to this. 8080 on your machine maps to 80 in the container. It serves two files:

curl -sI localhost:8080/index.html | grep -E 'HTTP|Content-Length'
curl -sI localhost:8080/50x.html | grep -E 'HTTP|Content-Length'
OutputHTTP/1.1 200 OKContent-Length: 615HTTP/1.1 200 OKContent-Length: 497

The tools

Tool For
curl Sending real requests, with -v to see them
nc Typing the protocol by hand
openssl s_client The same, but inside TLS

curl -v

-v prints the conversation. > is sent, < is received:

curl -sv localhost:8080 -o /dev/null 2>&1 \
  | grep -E '^[<>]' | head -10
Output> GET / HTTP/1.1> Host: localhost:8080> User-Agent: curl/8.7.1> Accept: */*> < HTTP/1.1 200 OK< Server: nginx/1.27.5< Date: <now>< Content-Type: text/html< Content-Length: 615

You typed a URL. curl added three headers, and the bare > is the blank line ending them.

Reading only what you need

-I sends HEAD and prints headers only:

curl -sI localhost:8080 | grep -E 'HTTP|Content-Type'
OutputHTTP/1.1 200 OKContent-Type: text/html

-i keeps the body as well:

curl -si localhost:8080 | grep -E 'HTTP/1.1|DOCTYPE'
OutputHTTP/1.1 200 OK<!DOCTYPE html>

-w prints chosen fields instead of the response:

curl -s -o /dev/null localhost:8080 \
  -w '%{http_code} %{size_download} %{content_type}'
Output200 615 text/html

Stateless

The server keeps nothing between requests:

curl -s -o /dev/null -w '%{http_code} ' localhost:8080
curl -s -o /dev/null -w '%{http_code}' localhost:8080
Output200 200

Logins, carts and sessions are built on top with cookies and tokens — chapter 9. Nothing in the protocol remembers you.

URLs

https://api.example.com:443/v1/users?page=2#top has six parts, and they do not all travel:

Part Value Sent
scheme https no — picks port and TLS
host api.example.com yes, as Host
port 443 no — picks where to connect
path /v1/users yes, in the request line
query ?page=2 yes, in the request line
fragment #top no

The query is sent:

curl -sv 'localhost:8080/?page=2&sort=new' -o /dev/null 2>&1 \
  | grep '^> GET'
Output> GET /?page=2&sort=new HTTP/1.1

The fragment is not:

curl -sv 'localhost:8080/#top' -o /dev/null 2>&1 | grep '^> GET'
Output> GET / HTTP/1.1

The host and port become one header, and the scheme vanishes:

curl -sv http://localhost:8080/ -o /dev/null 2>&1 \
  | grep -E '^> (GET|Host)'
Output> GET / HTTP/1.1> Host: localhost:8080