##// END OF EJS Templates
httppeer: use compression engine API for decompressing responses...
Gregory Szorc -
r30465:40a1871e default
parent child Browse files
Show More
@@ -12,7 +12,6 b' import errno'
12 12 import os
13 13 import socket
14 14 import tempfile
15 import zlib
16 15
17 16 from .i18n import _
18 17 from .node import nullid
@@ -30,16 +29,26 b' httplib = util.httplib'
30 29 urlerr = util.urlerr
31 30 urlreq = util.urlreq
32 31
33 def zgenerator(f):
34 zd = zlib.decompressobj()
32 # FUTURE: consider refactoring this API to use generators. This will
33 # require a compression engine API to emit generators.
34 def decompressresponse(response, engine):
35 35 try:
36 for chunk in util.filechunkiter(f):
37 while chunk:
38 yield zd.decompress(chunk, 2**18)
39 chunk = zd.unconsumed_tail
36 reader = engine.decompressorreader(response)
40 37 except httplib.HTTPException:
41 38 raise IOError(None, _('connection ended unexpectedly'))
42 yield zd.flush()
39
40 # We need to wrap reader.read() so HTTPException on subsequent
41 # reads is also converted.
42 origread = reader.read
43 class readerproxy(reader.__class__):
44 def read(self, *args, **kwargs):
45 try:
46 return origread(*args, **kwargs)
47 except httplib.HTTPException:
48 raise IOError(None, _('connection ended unexpectedly'))
49
50 reader.__class__ = readerproxy
51 return reader
43 52
44 53 class httppeer(wireproto.wirepeer):
45 54 def __init__(self, ui, path):
@@ -202,7 +211,7 b' class httppeer(wireproto.wirepeer):'
202 211 (safeurl, version))
203 212
204 213 if _compressible:
205 return util.chunkbuffer(zgenerator(resp))
214 return decompressresponse(resp, util.compengines['zlib'])
206 215
207 216 return resp
208 217
General Comments 0
You need to be logged in to leave comments. Login now