Skip to content
shellhacks.dev
APIs

Show only the response headers

Show only the response headers with curl, either by sending a HEAD request or by dumping the headers of a real GET with -D - and dropping the body.

1 min read
Summarize in AI

You need the response headers of a URL, and there are two ways to get them that are not equivalent.

Shell
curl -sI http://127.0.0.1:8000/index.txt | grep -E '^(HTTP|Content-)'
echo ---
curl -s -D - -o /dev/null http://127.0.0.1:8000/index.txt | grep -E '^(HTTP|Content-)'
Text
HTTP/1.0 200 OK
Content-type: text/plain
Content-Length: 6
---
HTTP/1.0 200 OK
Content-type: text/plain
Content-Length: 6

-I changes the method to HEAD, so the server sends headers and no body. -D - writes the received headers to standard output while the normal GET goes ahead and -o /dev/null throws the body away. Both are in the curl manual. The output of the two runs is the same here, because this server answers HEAD and GET alike.

A server is allowed to answer HEAD differently, and many frameworks route it to a different handler or return 405 for it. If the headers of a real request matter, as in a cache or a content-length check, use -D - instead of -I.

Taggedcurlhttp
Share

More snippets

APIs

Save a download with its remote name

Save a download under the name in the URL with curl -O. It writes to the current directory, and a URL that ends in a slash has no name to use.

1 min read
APIs

Send a custom header

Send a custom request header with curl -H 'Name: value'. A header with an empty value after a colon removes one of curl's defaults, such as User-Agent.

1 min read

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.