##// END OF EJS Templates
httppeer: don't accept very old media types (BC)...
Gregory Szorc -
r37572:301a1d2e default
parent child Browse files
Show More
@@ -123,12 +123,6 b' The ``application/hg-error`` media type '
123 The content of the HTTP response body typically holds text describing the
123 The content of the HTTP response body typically holds text describing the
124 error.
124 error.
125
125
126 The ``application/hg-changegroup`` media type indicates a changegroup response
127 type.
128
129 Clients also accept the ``text/plain`` media type. All other media
130 types should cause the client to error.
131
132 Behavior of media types is further described in the ``Content Negotiation``
126 Behavior of media types is further described in the ``Content Negotiation``
133 section below.
127 section below.
134
128
@@ -322,46 +322,40 b' def parsev1commandresponse(ui, baseurl, '
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))
343
344 # TODO consider switching to a decompression reader that uses
345 # generators.
346 if version_info == (0, 1):
347 if compressible:
348 resp = util.compengines['zlib'].decompressorreader(resp)
349
341
350 return respurl, resp
342 # TODO consider switching to a decompression reader that uses
343 # generators.
344 if version_info == (0, 1):
345 if compressible:
346 resp = util.compengines['zlib'].decompressorreader(resp)
351
347
352 elif version_info == (0, 2):
348 elif version_info == (0, 2):
353 # application/mercurial-0.2 always identifies the compression
349 # application/mercurial-0.2 always identifies the compression
354 # engine in the payload header.
350 # engine in the payload header.
355 elen = struct.unpack('B', resp.read(1))[0]
351 elen = struct.unpack('B', resp.read(1))[0]
356 ename = resp.read(elen)
352 ename = resp.read(elen)
357 engine = util.compengines.forwiretype(ename)
353 engine = util.compengines.forwiretype(ename)
358 return respurl, engine.decompressorreader(resp)
359 else:
360 raise error.RepoError(_("'%s' uses newer protocol %s") %
361 (safeurl, version))
362
354
363 if compressible:
355 resp = engine.decompressorreader(resp)
364 resp = util.compengines['zlib'].decompressorreader(resp)
356 else:
357 raise error.RepoError(_("'%s' uses newer protocol %s") %
358 (safeurl, version))
365
359
366 return respurl, resp
360 return respurl, resp
367
361
General Comments 0
You need to be logged in to leave comments. Login now