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