Skip to content

Instantly share code, notes, and snippets.

@deoren
Created January 22, 2018 03:47
Show Gist options
  • Select an option

  • Save deoren/0640ddec10738067fcf4069728753a36 to your computer and use it in GitHub Desktop.

Select an option

Save deoren/0640ddec10738067fcf4069728753a36 to your computer and use it in GitHub Desktop.
Small Python script to fetch/display HTTP response headers from web server
#!/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())
@deoren
Copy link
Author

deoren commented Jan 23, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment