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

Changeset 2490

Show
Ignore:
Timestamp:
08/04/09 23:53:06
Author:
fumanchu
Message:

python3: Better error message on bad request header. See #941.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/python3/cherrypy/test/test.py

    r2479 r2490  
    459459        'test_encoding', 
    460460        'test_etags', 
    461         #'test_http', 
     461        'test_http', 
    462462        'test_httpauth', 
    463463        'test_httplib', 
  • branches/python3/cherrypy/test/test_http.py

    r2438 r2490  
    145145        self.assertEqual(response.fp.read(22), b"Malformed Request-Line") 
    146146        c.close() 
    147  
     147     
     148    def test_malformed_header(self): 
     149        if self.scheme == 'https': 
     150            c = http.client.HTTPSConnection('%s:%s' % (self.interface(), self.PORT)) 
     151        else: 
     152            c = http.client.HTTPConnection('%s:%s' % (self.interface(), self.PORT)) 
     153        c.putrequest('GET', '/') 
     154        c.putheader('Content-Type', 'text/plain') 
     155        # See http://www.cherrypy.org/ticket/941  
     156        c._output(b'Re, 1.2.3.4#015#012') 
     157        c.endheaders() 
     158         
     159        response = c.getresponse() 
     160        self.status = str(response.status) 
     161        self.assertStatus(400) 
     162        self.body = response.fp.read(20) 
     163        self.assertBody("Illegal header line.") 
     164     
    148165    def test_http_over_https(self): 
    149166        if self.scheme != 'https': 
  • branches/python3/cherrypy/wsgiserver/__init__.py

    r2487 r2490  
    550550                v = line.strip().decode('ISO-8859-1') 
    551551            else: 
    552                 k, v = line.split(b":", 1) 
     552                try: 
     553                    k, v = line.split(b":", 1) 
     554                except ValueError: 
     555                    raise ValueError("Illegal header line.") 
    553556                k = k.strip().decode('ISO-8859-1').upper() 
    554557                v = v.strip().decode('ISO-8859-1') 

Hosted by WebFaction

Log in as guest/cpguest to create tickets