40
40
ConnectedTransport,
43
# TODO: This is not used anymore by HttpTransport_urllib
44
# (extracting the auth info and prompting the user for a password
45
# have been split), only the tests still use it. It should be
46
# deleted and the tests rewritten ASAP to stay in sync.
47
def extract_auth(url, password_manager):
48
"""Extract auth parameters from am HTTP/HTTPS url and add them to the given
49
password manager. Return the url, minus those auth parameters (which
52
if not re.match(r'^(https?)(\+\w+)?://', url):
54
'invalid absolute url %r' % (url,))
55
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
58
auth, netloc = netloc.split('@', 1)
60
username, password = auth.split(':', 1)
62
username, password = auth, None
64
host = netloc.split(':', 1)[0]
67
username = urlutils.unquote(username)
68
if password is not None:
69
password = urlutils.unquote(password)
71
password = ui.ui_factory.get_password(
72
prompt=u'HTTP %(user)s@%(host)s password',
73
user=username, host=host)
74
password_manager.add_password(None, host, username, password)
75
url = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
44
79
class HttpTransportBase(ConnectedTransport):
45
80
"""Base class for http implementations.
84
119
:param relpath: The relative path to the file
86
121
code, response_file = self._get(relpath, None)
122
# FIXME: some callers want an iterable... One step forward, three steps
123
# backwards :-/ And not only an iterable, but an iterable that can be
124
# seeked backwards, so we will never be able to do that. One such
125
# known client is bzrlib.bundle.serializer.v4.get_bundle_reader. At the
126
# time of this writing it's even the only known client -- vila20071203
127
return StringIO(response_file.read())
89
129
def _get(self, relpath, ranges, tail_amount=0):
90
130
"""Get a file, or part of a file.
202
242
# Split the received chunk
203
243
for offset, size in cur_coal.ranges:
204
244
start = cur_coal.start + offset
205
rfile.seek(start, os.SEEK_SET)
206
246
data = rfile.read(size)
207
247
data_len = len(data)
208
248
if data_len != size: