Response Headers
Lesson 23 of 47 in Coddy's Networking with the Terminal course.
After the status line the server sends headers: facts about the response, one per line, in the form Name: value.
The ones you will read constantly:
- Content-Type: what the body is.
text/html,application/json. Clients use this to decide how to read it. - Content-Length: how many bytes the body is.
- Location: on a 3xx, where to go instead.
curl -I asks for the headers only, using the HEAD method, so you can inspect a response without downloading a large body.
curl -sI http://127.0.0.1:9113/index.htmlHeader names are case insensitive, so a server may send Content-Type or content-type and both are correct. Search for them with grep -i or you will miss matches.
Challenge
MediumInspect a response without downloading it.
Serve a folder containing index.html on port 9113, then fetch the headers only and print just the content type line. Expected output:
Content-type: text/htmlMatch it case insensitively and anchor to the start of the line:
grep -i "^content-type". Do not print the whole header block, since it also contains a date that changes every second.
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