HTTP response headers provide essential details about the server's response, including status, caching, and security settings, playing a key role in diagnosing issues, optimizing performance, and enhancing security.
Understanding these headers aids in debugging, troubleshooting, and comprehending server response mechanisms to requests.
cURL, by default, displays only the response body but can also be configured to display the response headers, providing a comprehensive insight into server interactions.
Steps to view HTTP response headers using cURL:
- Open the terminal or command prompt on your computer.
- Make a standard cURL request to a desired URL.
$ 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.
- View the headers and the content using the -i or --include option.
$ 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
- Only see headers and exclude the body using the -I or --head option.
$ 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
- View verbose output, including request and response headers, using the -v or --verbose option.
$ 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.
- Save the headers to a file using the -o or --output option followed by the filename.
$ 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.
- Examine the saved request header file.
$ 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
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.