~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-10-13 06:41:04 UTC
  • mfrom: (2018.2.29 hpss HTTP support)
  • mto: This revision was merged to the branch mainline in revision 2075.
  • Revision ID: john@arbash-meinel.com-20061013064104-57dbb43c2ffa55ff
(Andrew Bennetts) Implement bzr+http which lets us tunnel the smart protocol through an http connection

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
        abspath = self._real_abspath(relpath)
96
96
        curl.setopt(pycurl.URL, abspath)
97
97
        self._set_curl_options(curl)
 
98
        curl.setopt(pycurl.HTTPGET, 1)
98
99
        # don't want the body - ie just do a HEAD request
99
100
        # This means "NO BODY" not 'nobody'
100
101
        curl.setopt(pycurl.NOBODY, 1)
115
116
            return self._get_full(relpath)
116
117
    
117
118
    def _setup_get_request(self, curl, relpath):
 
119
        # Make sure we do a GET request. versions > 7.14.1 also set the
 
120
        # NO BODY flag, but we'll do it ourselves in case it is an older
 
121
        # pycurl version
 
122
        curl.setopt(pycurl.NOBODY, 0)
 
123
        curl.setopt(pycurl.HTTPGET, 1)
 
124
        return self._setup_request(curl, relpath)
 
125
 
 
126
    def _setup_request(self, curl, relpath):
118
127
        """Do the common setup stuff for making a request
119
128
 
120
129
        :param curl: The curl object to place the request on
127
136
        abspath = self._real_abspath(relpath)
128
137
        curl.setopt(pycurl.URL, abspath)
129
138
        self._set_curl_options(curl)
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
139
 
136
140
        data = StringIO()
137
141
        header = StringIO()
179
183
        # handle_response will raise NoSuchFile, etc based on the response code
180
184
        return code, response.handle_response(abspath, code, headers, data)
181
185
 
 
186
    def _post(self, body_bytes):
 
187
        fake_file = StringIO(body_bytes)
 
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.
 
192
        curl.setopt(pycurl.POST, 1)
 
193
        curl.setopt(pycurl.POSTFIELDSIZE, len(body_bytes))
 
194
        curl.setopt(pycurl.READFUNCTION, fake_file.read)
 
195
        abspath, data, header = self._setup_request(curl, '.bzr/smart')
 
196
        self._curl_perform(curl)
 
197
        data.seek(0)
 
198
        code = curl.getinfo(pycurl.HTTP_CODE)
 
199
        headers = _extract_headers(header.getvalue(), abspath)
 
200
        return code, response.handle_response(abspath, code, headers, data)
 
201
 
182
202
    def _raise_curl_http_error(self, curl, info=None):
183
203
        code = curl.getinfo(pycurl.HTTP_CODE)
184
204
        url = curl.getinfo(pycurl.EFFECTIVE_URL)
194
214
        # There's no way in http/1.0 to say "must revalidate"; we don't want
195
215
        # to force it to always retrieve.  so just turn off the default Pragma
196
216
        # provided by Curl.
 
217
        # Also, we override the Expect: header so that pycurl will send the POST
 
218
        # body immediately.
197
219
        headers = ['Cache-control: max-age=0',
198
220
                   'Pragma: no-cache',
199
 
                   'Connection: Keep-Alive']
 
221
                   'Connection: Keep-Alive',
 
222
                   'Expect: ',]
200
223
        ## curl.setopt(pycurl.VERBOSE, 1)
201
224
        # TODO: maybe include a summary of the pycurl version
202
225
        ua_str = 'bzr/%s (pycurl)' % (bzrlib.__version__,)