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

Changeset 1259

Show
Ignore:
Timestamp:
08/21/06 01:12:54
Author:
fumanchu
Message:

Support for max_request_body_size when decoding chunked request body (also fixes a long-standing bug when max header size exceeded).

Files:

Legend:

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

    r1257 r1259  
    128128            _cpwsgiserver.HTTPRequest.parse_request(self) 
    129129        except http.MaxSizeExceeded: 
    130             self.simple_response(413, "Request Entity Too Large") 
     130            self.simple_response("413 Request Entity Too Large") 
    131131            cherrypy.log(traceback=True) 
     132     
     133    def decode_chunked(self): 
     134        """Decode the 'chunked' transfer coding.""" 
     135        if isinstance(self.rfile, http.SizeCheckWrapper): 
     136            self.rfile = self.rfile.rfile 
     137        mbs = int(cherrypy.config.get('server.max_request_body_size', 
     138                                      100 * 1024 * 1024)) 
     139        if mbs > 0: 
     140            self.rfile = http.SizeCheckWrapper(self.rfile, mbs) 
     141        try: 
     142            return _cpwsgiserver.HTTPRequest.decode_chunked(self) 
     143        except http.MaxSizeExceeded: 
     144            self.simple_response("413 Request Entity Too Large") 
     145            cherrypy.log(traceback=True) 
     146            return False 
    132147 
    133148 
  • trunk/cherrypy/_cpwsgiserver.py

    r1258 r1259  
    218218            cl += chunk_size 
    219219            data.write(self.rfile.read(chunk_size)) 
    220             if self.rfile.read(2) != "\r\n": 
     220            crlf = self.rfile.read(2) 
     221            if crlf != "\r\n": 
    221222                self.simple_response("400 Bad Request", 
    222                                      "Bad chunked transfer coding") 
     223                                     "Bad chunked transfer coding " 
     224                                     "(expected '\\r\\n', got %r)" % crlf) 
    223225                return 
    224226         
  • trunk/cherrypy/test/test_conn.py

    r1258 r1259  
    4040    cherrypy.config.update({ 
    4141        'log_to_screen': False, 
     42        'server.max_request_body_size': 100, 
    4243        'show_tracebacks': True, 
    4344        'environment': 'production', 
     
    186187        self.assertStatus('200 OK') 
    187188        self.assertBody("thanks for 'xx\r\nxxxxyyyyy' (application/x-json)") 
     189         
     190        # Try a chunked request that exceeds max_request_body_size. 
     191        # Note that the delimiters and trailer are included. 
     192        body = ("5f\r\n" + ("x" * 95) + "\r\n0\r\n\r\n") 
     193        self.getPage("/upload", 
     194                     headers=[("Transfer-Encoding", "chunked"), 
     195                              ("Content-Type", "text/plain"), 
     196                              ("Content-Length", len(body)), 
     197                              ], 
     198                     body=body, method="POST") 
     199        self.assertStatus(413) 
     200        self.assertBody("") 
    188201     
    189202    def test_HTTP10(self): 
  • trunk/cherrypy/test/test_core.py

    r1243 r1259  
    864864        self.getPage("/", headers=[('From', "x" * 500)]) 
    865865        self.assertStatus(413) 
    866         self.assertInBody("Request Entity Too Large") 
    867866         
    868867        # Test for http://www.cherrypy.org/ticket/421 
     
    893892        self.getPage('/upload', h, "POST", b) 
    894893        self.assertStatus(413) 
    895         self.assertInBody("Request Entity Too Large") 
    896894     
    897895    def testEmptyThreadlocals(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets