Show headers only when follow multiple redirects in curl

Sometimes its needed to figure out what redirects are done in background before we will see final page.

The best is to use curl with following options. We checking “nyt.com”:

curl -s -L -D - nyt.com -o /dev/null

The output from above command:

HTTP/1.1 301 Moved Permanently
Server: Apache
Location: http://www.nytimes.com
Content-Type: text/html; charset=iso-8859-1
Accept-Ranges: bytes
X-PageType: legacy-override
X-Age: 0
X-Origin-Time: 2017-06-29 09:26:20 EDT
Content-Length: 230
Accept-Ranges: bytes
Date: Thu, 29 Jun 2017 13:26:20 GMT
X-Frame-Options: DENY
Set-Cookie: vi_www_hp=z09; path=/; domain=.nytimes.com; expires=Tue, 01 Jan 2019 00:00:00 GMT
Connection: close
X-API-Version: F-5-4
X-Served-By: cache-hhn1537-HHN
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1498742781.530421,VS0,VE188
Vary: Fastly-SSL

HTTP/1.1 301 Moved Permanently
Server: Varnish
Retry-After: 0
Content-Length: 0
Location: https://www.nytimes.com/
Accept-Ranges: bytes
Date: Thu, 29 Jun 2017 13:26:20 GMT
X-Frame-Options: DENY
Set-Cookie: nyt-a=e99427a83c8ed796bece942b28274f524a66e9723fe6adc95a5062fbebb874f8; Expires=Fri, 29 Jun 2018 13:26:20 GMT; Path=/; Domain=.nytimes.com
Connection: close
X-API-Version: F-0
X-PageType: homepage
X-Served-By: cache-hhn1522-HHN
X-Cache: HIT
X-Cache-Hits: 0
X-Timer: S1498742781.920624,VS0,VE0

HTTP/1.1 200 OK
Server: Apache
Cache-Control: no-cache
X-ESI: 1
Content-Type: text/html; charset=utf-8
X-PageType: homepage
X-Age: 561
X-Origin-Time: 2017-06-29 09:24:27 EDT
Content-Length: 230912
Accept-Ranges: bytes
Date: Thu, 29 Jun 2017 13:26:21 GMT
Age: 113
X-Frame-Options: DENY
Set-Cookie: vi_www_hp=z09; path=/; domain=.nytimes.com; expires=Tue, 01 Jan 2019 00:00:00 GMT
Set-Cookie: nyt-a=6ce076bd9bb62c3f026bed82e91a3f54de533ad57dbe0d2633fce5bcfcfdae88; Expires=Fri, 29 Jun 2018 13:26:21 GMT; Path=/; Domain=.nytimes.com
Connection: close
X-API-Version: F-5-5
Content-Security-Policy: default-src data: 'unsafe-inline' 'unsafe-eval' https:; script-src data: 'unsafe-inline' 'unsafe-eval' https: blob:; style-src data: 'unsafe-inline' https:; img-src data: https: blob:; font-src data: https:; connect-src https: wss:; media-src https: blob:; object-src https:; child-src https: data: blob:; form-action https:; block-all-mixed-content;
X-Served-By: cache-hhn1540-HHN
X-Cache: HIT
X-Cache-Hits: 1
X-Timer: S1498742781.100679,VS0,VE1
Vary: Host, Accept-Encoding, Fastly-SSL

 

Leave a Comment.