290
293
return code, response.handle_response(abspath, code, msg, data)
293
def _raise_curl_http_error(self, curl, info=None):
296
def _raise_curl_http_error(self, curl, info=None, body=None):
297
"""Common curl->bzrlib error translation.
299
Some methods may choose to override this for particular cases.
301
The URL and code are automatically included as appropriate.
303
:param info: Extra information to include in the message.
305
:param body: File-like object from which the body of the page can be
294
308
code = curl.getinfo(pycurl.HTTP_CODE)
295
309
url = curl.getinfo(pycurl.EFFECTIVE_URL)
296
# Some error codes can be handled the same way for all
311
response_body = body.read()
312
plaintext_body = unhtml_roughly(response_body)
299
317
raise errors.TransportError(
300
318
'Server refuses to fulfill the request (403 Forbidden)'
319
' for %s: %s' % (url, plaintext_body))
306
324
msg = ': ' + info
307
325
raise errors.InvalidHttpResponse(
308
url, 'Unable to handle http code %d%s' % (code,msg))
326
url, 'Unable to handle http code %d%s: %s'
327
% (code, msg, plaintext_body))
310
329
def _debug_cb(self, kind, text):
311
if kind in (pycurl.INFOTYPE_HEADER_IN, pycurl.INFOTYPE_DATA_IN,
312
pycurl.INFOTYPE_SSL_DATA_IN):
330
if kind in (pycurl.INFOTYPE_HEADER_IN, pycurl.INFOTYPE_DATA_IN):
313
331
self._report_activity(len(text), 'read')
314
332
if (kind == pycurl.INFOTYPE_HEADER_IN
315
333
and 'http' in debug.debug_flags):
316
mutter('< %s' % text)
317
elif kind in (pycurl.INFOTYPE_HEADER_OUT, pycurl.INFOTYPE_DATA_OUT,
318
pycurl.INFOTYPE_SSL_DATA_OUT):
334
trace.mutter('< %s' % (text.rstrip(),))
335
elif kind in (pycurl.INFOTYPE_HEADER_OUT, pycurl.INFOTYPE_DATA_OUT):
319
336
self._report_activity(len(text), 'write')
320
337
if (kind == pycurl.INFOTYPE_HEADER_OUT
321
338
and 'http' in debug.debug_flags):
322
mutter('> %s' % text)
340
for line in text.rstrip().splitlines():
341
# People are often told to paste -Dhttp output to help
342
# debug. Don't compromise credentials.
344
header, details = line.split(':', 1)
347
if header in ('Authorization', 'Proxy-Authorization'):
348
line = '%s: <masked>' % (header,)
350
trace.mutter('> ' + '\n> '.join(lines))
323
351
elif kind == pycurl.INFOTYPE_TEXT and 'http' in debug.debug_flags:
324
mutter('* %s' % text)
352
trace.mutter('* %s' % text.rstrip())
353
elif (kind in (pycurl.INFOTYPE_TEXT, pycurl.INFOTYPE_SSL_DATA_IN,
354
pycurl.INFOTYPE_SSL_DATA_OUT)
355
and 'http' in debug.debug_flags):
356
trace.mutter('* %s' % text)
326
358
def _set_curl_options(self, curl):
327
359
"""Set options for all requests"""