Hi there,
I've seen a few queries in the list archives about this. This is what
I use:
GZIP_PAT = re.compile('^Mozilla/[5,6,7,8,9]|.*MSIE [6,7,8,9].*')
def gzip_response(resp):
accepts = web.ctx.env.get('HTTP_ACCEPT_ENCODING',None)
if accepts and accepts.find('gzip') > -1:
browser = web.ctx.env.get('HTTP_USER_AGENT',None)
if browser and GZIP_PAT.match(browser): #ok to compress for
this browser
web.webapi.header('Content-Encoding','gzip')
zbuf = cStringIO.StringIO()
zfile = gzip.GzipFile(mode='wb', fileobj=zbuf,
compresslevel=9)
zfile.write(resp)
zfile.close()
data = zbuf.getvalue()
web.webapi.header('Content-Length',str(len(data)))
web.webapi.header('Vary','Accept-Encoding', unique=True)
#don't vary by user-agent, defeats caching
return data
return resp
class foo:
def GET(self,whatever):
...
print gzip_response( render.foo( whatever ))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---