Check the status code and response headers without downloading the body — handy for auditing cache policy, content type, and redirects.
Check the status code and response headers without downloading the body — handy for auditing cache policy, content type, and redirects.
# -I sends HEAD and prints only headers:
curl -I https://example.com
# -i sends the full request and prints headers + body:
curl -i https://example.com
# -D - dumps headers to stdout while saving the body:
curl -D - -o page.html https://example.comconst res = await fetch('https://example.com');
console.log(res.status, res.statusText);
for (const [k, v] of res.headers) console.log(`${k}: ${v}`);
console.log(res.headers.get('content-type'));import requests
res = requests.head('https://example.com') # or .get()
print(res.status_code)
for k, v in res.headers.items():
print(f'{k}: {v}')curl's `-I` (capital) sends a HEAD request and prints headers only. Use `-i` (lowercase) to also see the body, or `-D -` to save the body to a file while dumping headers to the screen. For servers that don't support HEAD, use `-i` with a GET.
In browser `fetch`, mind the CORS restriction: on cross-origin responses you can only read headers the server explicitly lists in `Access-Control-Expose-Headers`. If `Content-Length` or custom headers appear missing, this is usually why.
Headers you'll read often include `Content-Type` (format and encoding), `Cache-Control` (cache lifetime), the `ETag` validator, `Location` (redirect target), and `X-RateLimit-*` (rate-limit info). Header names are case-insensitive, so `get('content-type')` in lowercase works fine.