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