~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_pycurl.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-08-28 09:22:17 UTC
  • mfrom: (3654.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080828092217-98wmtek2p8cie8sc
(vila) Fix bug #225020 by catching CURLE_SEND_ERROR

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
95
96
 
96
97
 
97
98
class PyCurlTransport(HttpTransportBase):
254
255
        return msg
255
256
 
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: '])
 
266
        try:
 
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)
 
274
                if code == 403:
 
275
                    raise errors.InvalidHttpResponse(
 
276
                        abspath,
 
277
                        'Unexpected send error,'
 
278
                        ' the server probably closed the connection')
 
279
            # Re-raise otherwise
 
280
            raise
269
281
        data.seek(0)
270
282
        code = curl.getinfo(pycurl.HTTP_CODE)
271
283
        msg = self._parse_headers(header)