Menu
Coddy logo textTech

Anatomy of a Request

Lesson 20 of 47 in Coddy's Networking with the Terminal course.

Underneath curl, an HTTP request is plain text sent over a socket. It starts with one line naming what you want:

GET /index.html HTTP/1.1

Three parts: the method (what kind of operation), the path (which thing), and the version. After that come headers, one per line, then a blank line, then an optional body.

The blank line is not decoration. It is how the server knows the headers have ended and the body, if any, begins. A request without it hangs, because the server is still waiting to hear the rest.

You can send one by hand. nc opens a raw connection and whatever you feed it goes straight down the wire:

printf 'GET / HTTP/1.0\r\n\r\n' | nc 127.0.0.1 9110

\r\n is the line ending HTTP requires, and the doubled one is that blank line.

challenge icon

Challenge

Hard

Skip curl entirely and speak HTTP yourself.

  1. Create index.html containing raw
  2. Serve the folder on port 9110
  3. Send a raw GET /index.html HTTP/1.0 request through nc and print only the first line of what comes back

That first line is the server's status line. Expected output:

HTTP/1.0 200 OK

Remember the blank line: printf 'GET /index.html HTTP/1.0\r\n\r\n'.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Networking with the Terminal

Practice on your own: Terminal playground