~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Changes in response to review: re-use _base_curl, rather than keeping a seperate _post_curl object; add docstring to test_http.RecordingServer, set is_user_error on some new exceptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
        if from_transport is not None:
78
78
            self._base_curl = from_transport._base_curl
79
79
            self._range_curl = from_transport._range_curl
80
 
            self._post_curl = from_transport._post_curl
81
80
        else:
82
81
            mutter('using pycurl %s' % pycurl.version)
83
82
            self._base_curl = pycurl.Curl()
84
83
            self._range_curl = pycurl.Curl()
85
 
            self._post_curl = pycurl.Curl()
86
84
 
87
85
    def should_cache(self):
88
86
        """Return True if the data pulled across should be cached locally.
97
95
        abspath = self._real_abspath(relpath)
98
96
        curl.setopt(pycurl.URL, abspath)
99
97
        self._set_curl_options(curl)
 
98
        curl.setopt(pycurl.HTTPGET, 1)
100
99
        # don't want the body - ie just do a HEAD request
101
100
        # This means "NO BODY" not 'nobody'
102
101
        curl.setopt(pycurl.NOBODY, 1)
186
185
 
187
186
    def _post(self, body_bytes):
188
187
        fake_file = StringIO(body_bytes)
189
 
        curl = self._post_curl
 
188
        curl = self._base_curl
 
189
        # Other places that use _base_curl for GET requests explicitly set
 
190
        # HTTPGET, so it should be safe to re-use the same object for both GETs
 
191
        # and POSTs.
190
192
        curl.setopt(pycurl.POST, 1)
191
193
        curl.setopt(pycurl.POSTFIELDSIZE, len(body_bytes))
192
194
        curl.setopt(pycurl.READFUNCTION, fake_file.read)