Mercurial > public > mercurial-scm > hg
comparison mercurial/httppeer.py @ 30464:e16e234b9ca3
httppeer: do decompression inside _callstream
The current HTTP transport protocol only compresses certain command
responses and requires calls to that command to call
"_callcompressable," which zlib decompresses the response
transparently.
Upcoming changes will enable *any* response to be compressed with
varying compression formats. In order to handle this better, this
commit moves the decompression bits to the main function performing
the HTTP request. We introduce an underscore-prefixed argument to
denote this behavior so it doesn't conflict with a named argument
to a command.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 19 Nov 2016 18:31:40 -0800 |
parents | cac4ca036dff |
children | 40a1871eea5e |
comparison
equal
deleted
inserted
replaced
30463:bc0def54c17d | 30464:e16e234b9ca3 |
---|---|
88 return self.caps | 88 return self.caps |
89 | 89 |
90 def lock(self): | 90 def lock(self): |
91 raise error.Abort(_('operation not supported over http')) | 91 raise error.Abort(_('operation not supported over http')) |
92 | 92 |
93 def _callstream(self, cmd, **args): | 93 def _callstream(self, cmd, _compressible=False, **args): |
94 if cmd == 'pushkey': | 94 if cmd == 'pushkey': |
95 args['data'] = '' | 95 args['data'] = '' |
96 data = args.pop('data', None) | 96 data = args.pop('data', None) |
97 headers = args.pop('headers', {}) | 97 headers = args.pop('headers', {}) |
98 | 98 |
199 "header (%s)") % (safeurl, proto)) | 199 "header (%s)") % (safeurl, proto)) |
200 if version_info > (0, 1): | 200 if version_info > (0, 1): |
201 raise error.RepoError(_("'%s' uses newer protocol %s") % | 201 raise error.RepoError(_("'%s' uses newer protocol %s") % |
202 (safeurl, version)) | 202 (safeurl, version)) |
203 | 203 |
204 if _compressible: | |
205 return util.chunkbuffer(zgenerator(resp)) | |
206 | |
204 return resp | 207 return resp |
205 | 208 |
206 def _call(self, cmd, **args): | 209 def _call(self, cmd, **args): |
207 fp = self._callstream(cmd, **args) | 210 fp = self._callstream(cmd, **args) |
208 try: | 211 try: |
269 if fh is not None: | 272 if fh is not None: |
270 fh.close() | 273 fh.close() |
271 os.unlink(filename) | 274 os.unlink(filename) |
272 | 275 |
273 def _callcompressable(self, cmd, **args): | 276 def _callcompressable(self, cmd, **args): |
274 stream = self._callstream(cmd, **args) | 277 return self._callstream(cmd, _compressible=True, **args) |
275 return util.chunkbuffer(zgenerator(stream)) | |
276 | 278 |
277 def _abort(self, exception): | 279 def _abort(self, exception): |
278 raise exception | 280 raise exception |
279 | 281 |
280 class httpspeer(httppeer): | 282 class httpspeer(httppeer): |