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

Changeset 2489

Show
Ignore:
Timestamp:
08/04/09 23:31:05
Author:
fumanchu
Message:

Better error message for illegal HTTP request headers. See #941.

Files:

Legend:

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

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

    r2488 r2489  
    528528                v = line.strip() 
    529529            else: 
    530                 k, v = line.split(":", 1) 
     530                try: 
     531                    k, v = line.split(":", 1) 
     532                except ValueError: 
     533                    raise ValueError("Illegal header line.") 
    531534                k, v = k.strip().upper(), v.strip() 
    532535                envname = "HTTP_" + k.replace("-", "_") 

Hosted by WebFaction

Log in as guest/cpguest to create tickets