Skip to content

kszongic/http-head-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@kszongic/http-head-cli

npm version npm downloads license node zero dependencies platform

Send HTTP HEAD requests and print response headers from the command line. Zero dependencies. Works on Windows, macOS, and Linux.

$ http-head example.com
HTTP/1.1 200 OK
content-type: text/html; charset=UTF-8
content-length: 1256
server: ECAcc (sac/254F)

Why?

Sometimes you just need to check headers β€” cache status, content type, redirects, CORS, security headers β€” without downloading the full response body. curl -I works, but it is not always available (Windows), and parsing its output is annoying.

http-head gives you:

  • πŸš€ Instant header inspection β€” HEAD requests download zero body bytes
  • πŸ“¦ JSON output β€” pipe directly into jq for scripting
  • πŸ”€ Redirect following β€” trace the full redirect chain
  • ⏱️ Custom timeouts β€” do not hang on slow servers
  • 🌐 Auto https:// β€” skip the protocol prefix, it just works

Install

npm i -g @kszongic/http-head-cli

Or run directly:

npx @kszongic/http-head-cli example.com

Usage

Print response headers

http-head https://example.com

Status code only

http-head -s https://example.com
# 200

JSON output

http-head -j https://example.com
# {"status":200,"headers":{"content-type":"text/html; charset=UTF-8",...}}

Follow redirects

http-head -L https://httpbin.org/redirect/2

Custom timeout

http-head -t 5000 https://example.com

Auto-prepend https://

http-head example.com
# Same as: http-head https://example.com

Options

Flag Description
-s, --status Print only the status code
-j, --json Output headers as JSON
-L, --follow Follow redirects (up to 10)
-t, --timeout Timeout in milliseconds (default: 10000)
-h, --help Show help
-v, --version Show version

Recipes

Check cache headers across CDN nodes

for i in 1 2 3 4 5; do
  echo "--- Request $i ---"
  http-head -j cdn.example.com | jq '.headers["x-cache"], .headers["cf-cache-status"]'
done

Verify security headers in CI

# GitHub Actions step β€” fail if missing security headers
HEADERS=$(http-head -j https://mysite.com)
echo "$HEADERS" | jq -e '.headers["strict-transport-security"]' || exit 1
echo "$HEADERS" | jq -e '.headers["x-content-type-options"]' || exit 1
echo "$HEADERS" | jq -e '.headers["x-frame-options"]' || exit 1
echo "All security headers present"

Monitor site uptime

STATUS=$(http-head -s https://api.example.com)
if [ "$STATUS" != "200" ]; then
  echo "API returned $STATUS"
fi

Trace redirect chains

http-head -L -j https://bit.ly/xyz | jq '.status'

Check content-type before downloading

TYPE=$(http-head -j https://api.example.com/data | jq -r '.headers["content-type"]')
if [[ "$TYPE" == *"application/json"* ]]; then
  curl -s https://api.example.com/data | jq .
else
  echo "Not JSON: $TYPE"
fi

Batch uptime check

for domain in example.com google.com github.com; do
  STATUS=$(http-head -s "$domain")
  echo "$domain -> $STATUS"
done

Use Cases

  • DevOps monitoring β€” Quick uptime and status checks without downloading bodies
  • Security audits β€” Verify HSTS, CSP, X-Frame-Options, and other security headers
  • CDN debugging β€” Check cache hit/miss, edge server, and age headers
  • API development β€” Verify content-type, CORS headers, and rate limit headers
  • CI/CD pipelines β€” Gate deployments on header compliance
  • Redirect debugging β€” Trace 301/302 chains for SEO or migration validation

How It Works

Uses Node.js built-in https (or http) module to send a HEAD request β€” the server returns headers only, no response body. This makes it extremely fast and bandwidth-efficient. No external dependencies, no native bindings.

Comparison

Tool Zero deps Cross-platform JSON output Follow redirects Status-only Install
http-head βœ… βœ… Win/Mac/Linux βœ… βœ… βœ… npx @kszongic/http-head-cli
curl -I N/A ⚠️ Not on Windows by default ❌ (needs parsing) βœ… -L ❌ (needs grep) Built-in (Unix)
wget --spider N/A ⚠️ Not on Windows ❌ βœ… ❌ Built-in (Linux)
httpie ❌ (Python) βœ… βœ… βœ… ❌ pip install httpie

Related Tools

License

MIT Β© kszongic

About

Send HTTP HEAD requests and print response headers from the CLI. Zero dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors