Menu
Coddy logo textTech

Custom Headers

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

-H adds a header to your request. This is how you tell a server who you are and what you can accept:

curl -s -H 'Accept: application/json' http://127.0.0.1:9118/

You can repeat -H as often as you like. The common ones are Accept (what format you want back), Content-Type (what format you are sending), and Authorization (your credentials).

The best way to learn what curl actually sends is to look. Put a listener in the way that answers the request and saves it to a file:

printf 'HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nok' \
  | nc -l -p 9118 > req.txt &

Now req.txt holds your exact request: the request line, every header, and the body. It is the single most useful debugging trick in this course.

challenge icon

Challenge

Expert

Send a header, then prove it arrived.

  1. Start a listener on port 9118 that replies HTTP/1.1 200 OK and saves the request into req.txt
  2. Make a request carrying the header X-Course: networking
  3. Print that header line back out of req.txt

Expected output:

X-Course: networking

Search case insensitively, and discard curl's own output so only the header prints.

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