cURL is widely used by developers, system administrators, and website owners to interact with web servers, make API requests, download files, and much more. When making requests, web servers don't just send back the data or content requested – they also send a set of HTTP headers. These headers offer valuable server response information, including meta-information, status, caching rules, and more.
Understanding HTTP headers is essential when diagnosing issues, optimizing performance, or inspecting security parameters. For instance, headers can give insights into server types, cache policies, security configurations, and redirection logic.
With cURL, you can easily fetch and examine these headers to better understand the behavior of web servers or applications. By default, cURL only displays the body of the response. However, you can instruct it to display headers for a more in-depth look into the server's response.
$ curl www.simplified.guide <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title> Simplified Guide </title> ##### snipped
Note that only the response body or content is displayed.
$ curl -i www.simplified.guide HTTP/1.1 200 OK Date: Tue, 26 Sep 2023 08:36:01 GMT Server: Apache X-Powered-By: PHP/8.2.10 Vary: Cookie Set-Cookie: DokuWiki=ka1l9l3j8d7i6rpj3ia3ppb13d; path=/; HttpOnly Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Set-Cookie: DW68700bfd16c2027de7de74a5a8202a6f=deleted; expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; path=/; HttpOnly Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title> Simplified Guide </title> ##### snipped
$ curl -I www.simplified.guide HTTP/1.1 200 OK Date: Tue, 26 Sep 2023 08:36:46 GMT Server: Apache X-Powered-By: PHP/8.2.10 Vary: Cookie Set-Cookie: DokuWiki=bin6f85ecq6bhlltr3vss3hm66; path=/; HttpOnly Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Set-Cookie: DW68700bfd16c2027de7de74a5a8202a6f=deleted; expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; path=/; HttpOnly Content-Type: text/html; charset=utf-8
$ curl -v www.simplified.guide * Trying 127.0.0.1:80... * Connected to www.simplified.guide (127.0.0.1) port 80 (#0) > GET / HTTP/1.1 > Host: www.simplified.guide > User-Agent: curl/8.1.2 > Accept: */* > < HTTP/1.1 200 OK < Date: Tue, 26 Sep 2023 08:37:09 GMT < Server: Apache < X-Powered-By: PHP/8.2.10 < Vary: Cookie < Set-Cookie: DokuWiki=3uod8b4v0n3fmvi1aj6r3c0vp0; path=/; HttpOnly < Expires: Thu, 19 Nov 1981 08:52:00 GMT < Cache-Control: no-store, no-cache, must-revalidate < Pragma: no-cache < Set-Cookie: DW68700bfd16c2027de7de74a5a8202a6f=deleted; expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; path=/; HttpOnly < Transfer-Encoding: chunked < Content-Type: text/html; charset=utf-8 < <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title> Simplified Guide </title> ##### snippped
Verbose mode is particularly useful for debugging connections, certificate issues, or understanding the full transaction process.
$ curl -I www.simplified.guide -o headers.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
This method is helpful when dealing with extensive headers or when you want to document server responses.
$ cat headers.txt HTTP/1.1 200 OK Date: Tue, 26 Sep 2023 08:40:00 GMT Server: Apache X-Powered-By: PHP/8.2.10 Vary: Cookie Set-Cookie: DokuWiki=1t1e1l3gn9qnm37c0j7dj01hki; path=/; HttpOnly Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Set-Cookie: DW68700bfd16c2027de7de74a5a8202a6f=deleted; expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; path=/; HttpOnly Content-Type: text/html; charset=utf-8
Comment anonymously. Login not required.