# HG changeset patch
# User Gregory Szorc <gregory.sz...@gmail.com>
# Date 1479609100 28800
#      Sat Nov 19 18:31:40 2016 -0800
# Node ID 0bef0b8fb9f44ed8568df6cfeabf162aa12b211e
# Parent  5a19e48cea056be5ece370744f3ee40bfb5d7c7e
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.

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -90,7 +90,7 @@ class httppeer(wireproto.wirepeer):
     def lock(self):
         raise error.Abort(_('operation not supported over http'))
 
-    def _callstream(self, cmd, **args):
+    def _callstream(self, cmd, _compressible=False, **args):
         if cmd == 'pushkey':
             args['data'] = ''
         data = args.pop('data', None)
@@ -201,6 +201,9 @@ class httppeer(wireproto.wirepeer):
                 raise error.RepoError(_("'%s' uses newer protocol %s") %
                                       (safeurl, version))
 
+        if _compressible:
+            return util.chunkbuffer(zgenerator(resp))
+
         return resp
 
     def _call(self, cmd, **args):
@@ -271,8 +274,7 @@ class httppeer(wireproto.wirepeer):
                 os.unlink(filename)
 
     def _callcompressable(self, cmd, **args):
-        stream = self._callstream(cmd, **args)
-        return util.chunkbuffer(zgenerator(stream))
+        return self._callstream(cmd, _compressible=True, **args)
 
     def _abort(self, exception):
         raise exception
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to