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.1Three 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
HardSkip curl entirely and speak HTTP yourself.
- Create
index.htmlcontainingraw - Serve the folder on port 9110
- Send a raw
GET /index.html HTTP/1.0request throughncand print only the first line of what comes back
That first line is the server's status line. Expected output:
HTTP/1.0 200 OKRemember the blank line:
printf 'GET /index.html HTTP/1.0\r\n\r\n'.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Networking with the Terminal
5HTTP by Hand
Anatomy of a RequestRequest MethodsStatus CodesResponse HeadersWriting a ResponseRecap: HTTP BasicsPractice on your own: Terminal playground