Changeset View
Changeset View
Standalone View
Standalone View
mercurial/httppeer.py
Show All 32 Lines | |||||
) | ) | ||||
from .interfaces import ( | from .interfaces import ( | ||||
repository, | repository, | ||||
util as interfaceutil, | util as interfaceutil, | ||||
) | ) | ||||
from .utils import ( | from .utils import ( | ||||
cborutil, | cborutil, | ||||
stringutil, | stringutil, | ||||
urlutil, | |||||
) | ) | ||||
httplib = util.httplib | httplib = util.httplib | ||||
urlerr = util.urlerr | urlerr = util.urlerr | ||||
urlreq = util.urlreq | urlreq = util.urlreq | ||||
def encodevalueinheaders(value, header, limit): | def encodevalueinheaders(value, header, limit): | ||||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Line(s) | try: | ||||
res = opener.open(req) | res = opener.open(req) | ||||
except urlerr.httperror as inst: | except urlerr.httperror as inst: | ||||
if inst.code == 401: | if inst.code == 401: | ||||
raise error.Abort(_(b'authorization failed')) | raise error.Abort(_(b'authorization failed')) | ||||
raise | raise | ||||
except httplib.HTTPException as inst: | except httplib.HTTPException as inst: | ||||
ui.debug( | ui.debug( | ||||
b'http error requesting %s\n' | b'http error requesting %s\n' | ||||
% util.hidepassword(req.get_full_url()) | % urlutil.hidepassword(req.get_full_url()) | ||||
) | ) | ||||
ui.traceback() | ui.traceback() | ||||
raise IOError(None, inst) | raise IOError(None, inst) | ||||
finally: | finally: | ||||
if ui.debugflag and ui.configbool(b'devel', b'debug.peer-request'): | if ui.debugflag and ui.configbool(b'devel', b'debug.peer-request'): | ||||
code = res.code if res else -1 | code = res.code if res else -1 | ||||
dbg( | dbg( | ||||
line | line | ||||
Show All 30 Lines | if baseurl.rstrip(b'/') != respurl.rstrip(b'/'): | ||||
if not ui.quiet: | if not ui.quiet: | ||||
ui.warn(_(b'real URL is %s\n') % respurl) | ui.warn(_(b'real URL is %s\n') % respurl) | ||||
try: | try: | ||||
proto = pycompat.bytesurl(resp.getheader('content-type', '')) | proto = pycompat.bytesurl(resp.getheader('content-type', '')) | ||||
except AttributeError: | except AttributeError: | ||||
proto = pycompat.bytesurl(resp.headers.get('content-type', '')) | proto = pycompat.bytesurl(resp.headers.get('content-type', '')) | ||||
safeurl = util.hidepassword(baseurl) | safeurl = urlutil.hidepassword(baseurl) | ||||
if proto.startswith(b'application/hg-error'): | if proto.startswith(b'application/hg-error'): | ||||
raise error.OutOfBandError(resp.read()) | raise error.OutOfBandError(resp.read()) | ||||
# Pre 1.0 versions of Mercurial used text/plain and | # Pre 1.0 versions of Mercurial used text/plain and | ||||
# application/hg-changegroup. We don't support such old servers. | # application/hg-changegroup. We don't support such old servers. | ||||
if not proto.startswith(b'application/mercurial-'): | if not proto.startswith(b'application/mercurial-'): | ||||
ui.debug(b"requested URL: '%s'\n" % util.hidepassword(requrl)) | ui.debug(b"requested URL: '%s'\n" % urlutil.hidepassword(requrl)) | ||||
msg = _( | msg = _( | ||||
b"'%s' does not appear to be an hg repository:\n" | b"'%s' does not appear to be an hg repository:\n" | ||||
b"---%%<--- (%s)\n%s\n---%%<---\n" | b"---%%<--- (%s)\n%s\n---%%<---\n" | ||||
) % (safeurl, proto or b'no content-type', resp.read(1024)) | ) % (safeurl, proto or b'no content-type', resp.read(1024)) | ||||
# Some servers may strip the query string from the redirect. We | # Some servers may strip the query string from the redirect. We | ||||
# raise a special error type so callers can react to this specially. | # raise a special error type so callers can react to this specially. | ||||
if redirected and qsdropped: | if redirected and qsdropped: | ||||
▲ Show 20 Lines • Show All 682 Lines • ▼ Show 20 Line(s) | def makepeer(ui, path, opener=None, requestbuilder=urlreq.request): | ||||
"""Construct an appropriate HTTP peer instance. | """Construct an appropriate HTTP peer instance. | ||||
``opener`` is an ``url.opener`` that should be used to establish | ``opener`` is an ``url.opener`` that should be used to establish | ||||
connections, perform HTTP requests. | connections, perform HTTP requests. | ||||
``requestbuilder`` is the type used for constructing HTTP requests. | ``requestbuilder`` is the type used for constructing HTTP requests. | ||||
It exists as an argument so extensions can override the default. | It exists as an argument so extensions can override the default. | ||||
""" | """ | ||||
u = util.url(path) | u = urlutil.url(path) | ||||
if u.query or u.fragment: | if u.query or u.fragment: | ||||
raise error.Abort( | raise error.Abort( | ||||
_(b'unsupported URL component: "%s"') % (u.query or u.fragment) | _(b'unsupported URL component: "%s"') % (u.query or u.fragment) | ||||
) | ) | ||||
# urllib cannot handle URLs with embedded user or passwd. | # urllib cannot handle URLs with embedded user or passwd. | ||||
url, authinfo = u.authinfo() | url, authinfo = u.authinfo() | ||||
ui.debug(b'using %s\n' % url) | ui.debug(b'using %s\n' % url) | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |