~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/__init__.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:
586
586
    def handle_one_request(self):
587
587
        """Handle a single HTTP request, by abruptly closing the connection"""
588
588
        self.close_connection = 1
 
589
 
 
590
 
 
591
class BadStatusRequestHandler(TestingHTTPRequestHandler):
 
592
    """Whatever request comes in, returns a bad status"""
 
593
 
 
594
    def parse_request(self):
 
595
        """Fakes handling a single HTTP request, returns a bad status"""
 
596
        ignored = TestingHTTPRequestHandler.parse_request(self)
 
597
        self.send_response(0, "Bad status")
 
598
        return False
 
599
 
 
600
 
 
601
class InvalidStatusRequestHandler(TestingHTTPRequestHandler):
 
602
    """Whatever request comes in, returns am invalid status"""
 
603
 
 
604
    def parse_request(self):
 
605
        """Fakes handling a single HTTP request, returns a bad status"""
 
606
        ignored = TestingHTTPRequestHandler.parse_request(self)
 
607
        self.wfile.write("Invalid status line\r\n")
 
608
        return False