267
268
# We override the Expect: header so that pycurl will send the POST
268
269
# body immediately.
270
self._curl_perform(curl, header, ['Expect: '])
271
self._curl_perform(curl, header,
273
'Content-Type: application/octet-stream'])
271
274
except pycurl.error, e:
272
275
if e[0] == CURLE_SEND_ERROR:
273
276
# When talking to an HTTP/1.0 server, getting a 400+ error code
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.
304
:param body: File-like object from which the body of the page can be read.
294
306
code = curl.getinfo(pycurl.HTTP_CODE)
295
307
url = curl.getinfo(pycurl.EFFECTIVE_URL)
296
# Some error codes can be handled the same way for all
309
response_body = body.read()
310
plaintext_body = unhtml_roughly(response_body)
299
315
raise errors.TransportError(
300
316
'Server refuses to fulfill the request (403 Forbidden)'
317
' for %s: %s' % (url, plaintext_body))
306
322
msg = ': ' + info
307
323
raise errors.InvalidHttpResponse(
308
url, 'Unable to handle http code %d%s' % (code,msg))
324
url, 'Unable to handle http code %d%s: %s'
325
% (code, msg, plaintext_body))
310
327
def _debug_cb(self, kind, text):
311
328
if kind in (pycurl.INFOTYPE_HEADER_IN, pycurl.INFOTYPE_DATA_IN,