Created
January 22, 2018 03:47
-
-
Save deoren/0640ddec10738067fcf4069728753a36 to your computer and use it in GitHub Desktop.
Small Python script to fetch/display HTTP response headers from web server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2.7 | |
| # Purpose: Look at HTTP Response headers from requested server. | |
| # Credit: http://stackoverflow.com/questions/843392/python-get-http-headers-from-urllib-call | |
| import httplib | |
| from pprint import pprint as ppr | |
| import sys | |
| HTTP_SERVER= sys.argv[1] | |
| # In most cases, we want the default document. | |
| REQUESTED_PAGE = "/" | |
| conn = httplib.HTTPConnection(HTTP_SERVER) | |
| conn.request("HEAD", REQUESTED_PAGE) | |
| res = conn.getresponse() | |
| print "\nStatus and Reason: %s %s" % (res.status, res.reason) | |
| # Example result: | |
| #200 OK | |
| print "\nHTTP Response headers: " | |
| ppr(res.getheaders()) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of the time this Gist entry was created, GitHub does not support notifications for comments for mentions to Gist entries (see isaacs/github#21 for details). Please contact me via Twitter or file an issue in the deoren/leave-feedback repo (created for that very purpose) if you wish to receive a response for your feedback. Thank you in advance!