Skip to content

Instantly share code, notes, and snippets.

@shimon
Created March 19, 2012 14:20
Show Gist options
  • Save shimon/2114028 to your computer and use it in GitHub Desktop.
Save shimon/2114028 to your computer and use it in GitHub Desktop.
Some code to check for gzip compression on an HTTP host
#!/usr/bin/python
import httplib
from pprint import pprint
if __name__ == "__main__":
url = "/"
#url = '/static/css/style.css'
conn = httplib.HTTPConnection('127.0.0.1')
conn.putrequest("GET", url, skip_host=True)
print "Requesting %s ..." % url
conn.putheader('Accept-encoding', 'gzip, deflate')
conn.putheader('Host', 'local.djangozoom.com')
conn.putheader('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0')
# Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
# Accept-Language: en-us,en;q=0.5
# Accept-Encoding: gzip, deflate
# Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
conn.endheaders()
res = conn.getresponse()
res_src = res.read()
pprint(res.status)
pprint(res.getheaders())
print "Response Gzipped? %s" % str(
res.getheader('content-encoding') == 'gzip')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment