Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 2041

Show
Ignore:
Timestamp:
09/27/08 16:04:45
Author:
fumanchu
Message:

Fix for #851 (malformed get request to wsgiserver results in traceback).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/test/test_http.py

    r1915 r2041  
    104104                          response_body) 
    105105 
     106    def test_malformed_request_line(self): 
     107        # Test missing version in Request-Line 
     108        if self.scheme == 'https': 
     109            c = httplib.HTTPSConnection('127.0.0.1:%s' % self.PORT) 
     110        else: 
     111            c = httplib.HTTPConnection('127.0.0.1:%s' % self.PORT) 
     112        c._output('GET /') 
     113        c._send_output() 
     114        response = c.response_class(c.sock, strict=c.strict, method='GET') 
     115        response.begin() 
     116        self.assertEqual(response.status, 400) 
     117        self.assertEqual(response.fp.read(), "Malformed Request-Line") 
     118        c.close() 
     119 
    106120 
    107121if __name__ == '__main__': 
  • trunk/cherrypy/wsgiserver/__init__.py

    r2038 r2041  
    333333        environ = self.environ 
    334334         
    335         method, path, req_protocol = request_line.strip().split(" ", 2) 
     335        try: 
     336            method, path, req_protocol = request_line.strip().split(" ", 2) 
     337        except ValueError: 
     338            self.simple_response(400, "Malformed Request-Line") 
     339            return 
     340         
    336341        environ["REQUEST_METHOD"] = method 
    337342         
     
    589594        if msg: 
    590595            buf.append(msg) 
    591         self.wfile.sendall("".join(buf)) 
     596         
     597        try: 
     598            self.wfile.sendall("".join(buf)) 
     599        except socket.error, x: 
     600            if x.args[0] not in socket_errors_to_ignore: 
     601                raise 
    592602     
    593603    def start_response(self, status, headers, exc_info = None): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets