92
92
CURLE_COULDNT_RESOLVE_PROXY = _get_pycurl_errcode('E_COULDNT_RESOLVE_PROXY', 5)
93
93
CURLE_GOT_NOTHING = _get_pycurl_errcode('E_GOT_NOTHING', 52)
94
94
CURLE_PARTIAL_FILE = _get_pycurl_errcode('E_PARTIAL_FILE', 18)
95
CURLE_SEND_ERROR = _get_pycurl_errcode('E_SEND_ERROR', 55)
97
98
class PyCurlTransport(HttpTransportBase):
256
257
def _post(self, body_bytes):
258
curl = self._get_curl()
259
abspath, data, header = self._setup_request(curl, '.bzr/smart')
260
curl.setopt(pycurl.POST, 1)
257
261
fake_file = StringIO(body_bytes)
258
curl = self._get_curl()
259
# Other places that use the Curl object (returned by _get_curl)
260
# for GET requests explicitly set HTTPGET, so it should be safe to
261
# re-use the same object for both GETs and POSTs.
262
curl.setopt(pycurl.POST, 1)
263
262
curl.setopt(pycurl.POSTFIELDSIZE, len(body_bytes))
264
263
curl.setopt(pycurl.READFUNCTION, fake_file.read)
265
abspath, data, header = self._setup_request(curl, '.bzr/smart')
266
264
# We override the Expect: header so that pycurl will send the POST
267
265
# body immediately.
268
self._curl_perform(curl, header, ['Expect: '])
267
self._curl_perform(curl, header, ['Expect: '])
268
except pycurl.error, e:
269
if e[0] == CURLE_SEND_ERROR:
270
# This has been observed when curl assumes a closed connection
271
# when talking to HTTP/1.0 servers, getting a 403, but trying
272
# to send the request body anyway. (see bug #225020)
273
code = curl.getinfo(pycurl.HTTP_CODE)
275
raise errors.InvalidHttpResponse(
277
'Unexpected send error,'
278
' the server probably closed the connection')
270
282
code = curl.getinfo(pycurl.HTTP_CODE)
271
283
msg = self._parse_headers(header)