~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-13 10:50:33 UTC
  • mfrom: (2077 +trunk)
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061013105033-7e091ff8dcc0ed0c
Merge bzr.dev. Including http modifications by "smart" related code

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
        abspath = self._real_abspath(relpath)
102
102
        curl.setopt(pycurl.URL, abspath)
103
103
        self._set_curl_options(curl)
 
104
        curl.setopt(pycurl.HTTPGET, 1)
104
105
        # don't want the body - ie just do a HEAD request
105
106
        # This means "NO BODY" not 'nobody'
106
107
        curl.setopt(pycurl.NOBODY, 1)
126
127
            return self._get_full(relpath)
127
128
 
128
129
    def _setup_get_request(self, curl, relpath):
 
130
        # Make sure we do a GET request. versions > 7.14.1 also set the
 
131
        # NO BODY flag, but we'll do it ourselves in case it is an older
 
132
        # pycurl version
 
133
        curl.setopt(pycurl.NOBODY, 0)
 
134
        curl.setopt(pycurl.HTTPGET, 1)
 
135
        return self._setup_request(curl, relpath)
 
136
 
 
137
    def _setup_request(self, curl, relpath):
129
138
        """Do the common setup stuff for making a request
130
139
 
131
140
        :param curl: The curl object to place the request on
138
147
        abspath = self._real_abspath(relpath)
139
148
        curl.setopt(pycurl.URL, abspath)
140
149
        self._set_curl_options(curl)
141
 
        # Make sure we do a GET request. versions > 7.14.1 also set the
142
 
        # NO BODY flag, but we'll do it ourselves in case it is an older
143
 
        # pycurl version
144
 
        curl.setopt(pycurl.NOBODY, 0)
145
 
        curl.setopt(pycurl.HTTPGET, 1)
146
150
 
147
151
        data = StringIO()
148
152
        header = StringIO()
191
195
        # handle_response will raise NoSuchFile, etc based on the response code
192
196
        return code, response.handle_response(abspath, code, headers, data)
193
197
 
 
198
    def _post(self, body_bytes):
 
199
        fake_file = StringIO(body_bytes)
 
200
        curl = self._base_curl
 
201
        # Other places that use _base_curl for GET requests explicitly set
 
202
        # HTTPGET, so it should be safe to re-use the same object for both GETs
 
203
        # and POSTs.
 
204
        curl.setopt(pycurl.POST, 1)
 
205
        curl.setopt(pycurl.POSTFIELDSIZE, len(body_bytes))
 
206
        curl.setopt(pycurl.READFUNCTION, fake_file.read)
 
207
        abspath, data, header = self._setup_request(curl, '.bzr/smart')
 
208
        self._curl_perform(curl)
 
209
        data.seek(0)
 
210
        code = curl.getinfo(pycurl.HTTP_CODE)
 
211
        headers = _extract_headers(header.getvalue(), abspath)
 
212
        return code, response.handle_response(abspath, code, headers, data)
 
213
 
194
214
    def _raise_curl_http_error(self, curl, info=None):
195
215
        code = curl.getinfo(pycurl.HTTP_CODE)
196
216
        url = curl.getinfo(pycurl.EFFECTIVE_URL)
211
231
        # There's no way in http/1.0 to say "must revalidate"; we don't want
212
232
        # to force it to always retrieve.  so just turn off the default Pragma
213
233
        # provided by Curl.
 
234
        # Also, we override the Expect: header so that pycurl will send the POST
 
235
        # body immediately.
214
236
        headers = ['Cache-control: max-age=0',
215
237
                   'Pragma: no-cache',
216
 
                   'Connection: Keep-Alive']
 
238
                   'Connection: Keep-Alive',
 
239
                   'Expect: ',]
217
240
        ## curl.setopt(pycurl.VERBOSE, 1)
218
241
        # TODO: maybe include a summary of the pycurl version
219
242
        ua_str = 'bzr/%s (pycurl)' % (bzrlib.__version__,)