-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessors.py
More file actions
31 lines (23 loc) · 797 Bytes
/
processors.py
File metadata and controls
31 lines (23 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#from models import engine
#from sqlalchemy.orm import scoped_session, sessionmaker
import cStringIO
import gzip
import web
#def load_sqlalchemy(handler):
# web.ctx.orm = scoped_session(sessionmaker(bind=engine))
# return handler()
def gzip_response(handler):
resp = handler()
accepts = web.ctx.env.get('HTTP_ACCEPT_ENCODING', None)
if not accepts or accepts.find('gzip') == -1:
return resp
resp = str(resp)
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)
return data