~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-04 14:42:05 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061004144205-6a7496410b893ab1
Add tests against erroneous http status lines.

* bzrlib/transport/http/_urllib2_wrappers.py:
(Response.begin): In some subtle cases we MUST not try to read the
response body.
(AbstractHTTPConnection.strict): Do not try to support HTTP/0.9 or we
may fail to detect bad status lines.
(AbstractHTTPHandler.do_open): Translate BasStatusLine into
InvalidHttpResponse and don't retry in that case.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport.has): 

* bzrlib/transport/http/__init__.py:
(BadStatusRequestHandler, InvalidStatusRequestHandler): New classes.

* bzrlib/tests/test_http.py:
(TestBadStatusServer.create_transport_server,
TestBadStatusServer_urllib, TestBadStatusServer_pycurl,
TestInvalidStatusServer, TestInvalidStatusServer_urllib,
TestInvalidStatusServer_pycurl): New classes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
        # don't want the body - ie just do a HEAD request
99
99
        # This means "NO BODY" not 'nobody'
100
100
        curl.setopt(pycurl.NOBODY, 1)
 
101
        # In some erroneous cases, pycurl will emit text on
 
102
        # stdout if we don't catch it (see InvalidStatus tests
 
103
        # for one such occurrence).
 
104
        blackhole = StringIO()
 
105
        curl.setopt(pycurl.WRITEFUNCTION, blackhole.write)
101
106
        self._curl_perform(curl)
102
107
        code = curl.getinfo(pycurl.HTTP_CODE)
103
108
        if code == 404: # not found
106
111
            return True
107
112
        else:
108
113
            self._raise_curl_http_error(curl)
109
 
        
 
114
 
110
115
    def _get(self, relpath, ranges, tail_amount=0):
111
116
        # This just switches based on the type of request
112
117
        if ranges is not None or tail_amount not in (0, None):
113
118
            return self._get_ranged(relpath, ranges, tail_amount=tail_amount)
114
119
        else:
115
120
            return self._get_full(relpath)
116
 
    
 
121
 
117
122
    def _setup_get_request(self, curl, relpath):
118
123
        """Do the common setup stuff for making a request
119
124