mercurial/httppeer.py
changeset 37554 301a1d2e8016
parent 37553 6b08cf6b900f
child 37555 930c433eb311
equal deleted inserted replaced
37553:6b08cf6b900f 37554:301a1d2e8016
   320         proto = pycompat.bytesurl(resp.headers.get(r'content-type', r''))
   320         proto = pycompat.bytesurl(resp.headers.get(r'content-type', r''))
   321 
   321 
   322     safeurl = util.hidepassword(baseurl)
   322     safeurl = util.hidepassword(baseurl)
   323     if proto.startswith('application/hg-error'):
   323     if proto.startswith('application/hg-error'):
   324         raise error.OutOfBandError(resp.read())
   324         raise error.OutOfBandError(resp.read())
   325     # accept old "text/plain" and "application/hg-changegroup" for now
   325 
   326     if not (proto.startswith('application/mercurial-') or
   326     # Pre 1.0 versions of Mercurial used text/plain and
   327             (proto.startswith('text/plain')
   327     # application/hg-changegroup. We don't support such old servers.
   328              and not resp.headers.get('content-length')) or
   328     if not proto.startswith('application/mercurial-'):
   329             proto.startswith('application/hg-changegroup')):
       
   330         ui.debug("requested URL: '%s'\n" % util.hidepassword(requrl))
   329         ui.debug("requested URL: '%s'\n" % util.hidepassword(requrl))
   331         raise error.RepoError(
   330         raise error.RepoError(
   332             _("'%s' does not appear to be an hg repository:\n"
   331             _("'%s' does not appear to be an hg repository:\n"
   333               "---%%<--- (%s)\n%s\n---%%<---\n")
   332               "---%%<--- (%s)\n%s\n---%%<---\n")
   334             % (safeurl, proto or 'no content-type', resp.read(1024)))
   333             % (safeurl, proto or 'no content-type', resp.read(1024)))
   335 
   334 
   336     if proto.startswith('application/mercurial-'):
   335     try:
   337         try:
   336         version = proto.split('-', 1)[1]
   338             version = proto.split('-', 1)[1]
   337         version_info = tuple([int(n) for n in version.split('.')])
   339             version_info = tuple([int(n) for n in version.split('.')])
   338     except ValueError:
   340         except ValueError:
   339         raise error.RepoError(_("'%s' sent a broken Content-Type "
   341             raise error.RepoError(_("'%s' sent a broken Content-Type "
   340                                 "header (%s)") % (safeurl, proto))
   342                                     "header (%s)") % (safeurl, proto))
   341 
   343 
   342     # TODO consider switching to a decompression reader that uses
   344         # TODO consider switching to a decompression reader that uses
   343     # generators.
   345         # generators.
   344     if version_info == (0, 1):
   346         if version_info == (0, 1):
   345         if compressible:
   347             if compressible:
   346             resp = util.compengines['zlib'].decompressorreader(resp)
   348                 resp = util.compengines['zlib'].decompressorreader(resp)
   347 
   349 
   348     elif version_info == (0, 2):
   350             return respurl, resp
   349         # application/mercurial-0.2 always identifies the compression
   351 
   350         # engine in the payload header.
   352         elif version_info == (0, 2):
   351         elen = struct.unpack('B', resp.read(1))[0]
   353             # application/mercurial-0.2 always identifies the compression
   352         ename = resp.read(elen)
   354             # engine in the payload header.
   353         engine = util.compengines.forwiretype(ename)
   355             elen = struct.unpack('B', resp.read(1))[0]
   354 
   356             ename = resp.read(elen)
   355         resp = engine.decompressorreader(resp)
   357             engine = util.compengines.forwiretype(ename)
   356     else:
   358             return respurl, engine.decompressorreader(resp)
   357         raise error.RepoError(_("'%s' uses newer protocol %s") %
   359         else:
   358                               (safeurl, version))
   360             raise error.RepoError(_("'%s' uses newer protocol %s") %
       
   361                                   (safeurl, version))
       
   362 
       
   363     if compressible:
       
   364         resp = util.compengines['zlib'].decompressorreader(resp)
       
   365 
   359 
   366     return respurl, resp
   360     return respurl, resp
   367 
   361 
   368 class httppeer(wireproto.wirepeer):
   362 class httppeer(wireproto.wirepeer):
   369     def __init__(self, ui, path, url, opener, requestbuilder, caps):
   363     def __init__(self, ui, path, url, opener, requestbuilder, caps):