Mercurial > hg
comparison mercurial/hgweb/protocol.py @ 30358:38130a0bbb99
hgweb: use compression engine API for zlib compression
More low-level compression code elimination because we now have nice
APIs.
This patch also demonstrates why we needed and implemented the
"level" option on the "compressstream" API.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Nov 2016 18:54:35 -0800 |
parents | d105195436c0 |
children | 038547a14d85 |
comparison
equal
deleted
inserted
replaced
30357:5925bda42dbd | 30358:38130a0bbb99 |
---|---|
86 | 86 |
87 def compresschunks(self, chunks): | 87 def compresschunks(self, chunks): |
88 # Don't allow untrusted settings because disabling compression or | 88 # Don't allow untrusted settings because disabling compression or |
89 # setting a very high compression level could lead to flooding | 89 # setting a very high compression level could lead to flooding |
90 # the server's network or CPU. | 90 # the server's network or CPU. |
91 z = zlib.compressobj(self.ui.configint('server', 'zliblevel', -1)) | 91 opts = {'level': self.ui.configint('server', 'zliblevel', -1)} |
92 for chunk in chunks: | 92 return util.compengines['zlib'].compressstream(chunks, opts) |
93 data = z.compress(chunk) | |
94 # Not all calls to compress() emit data. It is cheaper to inspect | |
95 # that here than to send it via the generator. | |
96 if data: | |
97 yield data | |
98 yield z.flush() | |
99 | 93 |
100 def _client(self): | 94 def _client(self): |
101 return 'remote:%s:%s:%s' % ( | 95 return 'remote:%s:%s:%s' % ( |
102 self.req.env.get('wsgi.url_scheme') or 'http', | 96 self.req.env.get('wsgi.url_scheme') or 'http', |
103 urlreq.quote(self.req.env.get('REMOTE_HOST', '')), | 97 urlreq.quote(self.req.env.get('REMOTE_HOST', '')), |