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

Changeset 1175

Show
Ignore:
Timestamp:
06/29/06 14:15:43
Author:
fumanchu
Message:

Fix for #528 (Allow request body parsing for methods other than "POST" and "PUT").

Files:

Legend:

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

    r1170 r1175  
    208208                 
    209209                if self.process_request_body: 
     210                    # Check path-specific methods_with_bodies. 
     211                    meths = self.config.get("methods_with_bodies", ("POST", "PUT")) 
     212                    self.process_request_body = self.method in meths 
     213                     
    210214                    # Prepare the SizeCheckWrapper for the request body 
    211215                    mbs = int(self.config.get('server.max_request_body_size', 
     
    240244         
    241245        self.method = method 
    242         self.process_request_body = method in ("POST", "PUT") 
    243          
    244246        self.path = path 
    245247        self.query_string = qs 
  • trunk/cherrypy/test/test_core.py

    r1168 r1175  
    1616 
    1717defined_http_methods = ("OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", 
    18                         "TRACE", "CONNECT"
     18                        "TRACE", "CONNECT", "PROPFIND"
    1919 
    2020 
     
    113113             
    114114            def index(self): 
    115                 raise NameError(
     115                raise NameError("redirect_test"
    116116            index.exposed = True 
    117117        error = Error() 
     
    373373        'server.max_request_header_size': 500, 
    374374        }) 
    375     cherrypy.tree.mount(root, conf={'/': {'log_access_file': log_access_file}}) 
     375    appconf = { 
     376        '/': {'log_access_file': log_access_file}, 
     377        '/method': {'methods_with_bodies': ("POST", "PUT", "PROPFIND")}, 
     378        } 
     379    cherrypy.tree.mount(root, conf=appconf) 
    376380 
    377381 
     
    766770     
    767771    def testHTTPMethods(self): 
     772        helper.webtest.methods_with_bodies = ("POST", "PUT", "PROPFIND") 
     773         
    768774        # Test that all defined HTTP methods work. 
    769775        for m in defined_http_methods: 
     
    785791         
    786792        # Request a PUT method with a file body 
    787         h = [("Content-type", "text/plain"), 
    788              ("Content-Length", "27")] 
    789          
    790         self.getPage("/method/request_body", headers=h, method="PUT", 
    791                        body="one thing on top of another") 
    792         self.assertBody("one thing on top of another") 
     793        b = "one thing on top of another" 
     794        h = [("Content-Type", "text/plain"), 
     795             ("Content-Length", str(len(b)))] 
     796        self.getPage("/method/request_body", headers=h, method="PUT", body=b) 
     797        self.assertStatus(200) 
     798        self.assertBody(b) 
     799         
     800        # Request a custom method with a request body 
     801        b = ('<?xml version="1.0" encoding="utf-8" ?>\n\n' 
     802             '<propfind xmlns="DAV:"><prop><getlastmodified/>' 
     803             '</prop></propfind>') 
     804        h = [('Content-Type', 'text/xml'), 
     805             ('Content-Length', str(len(b)))] 
     806        self.getPage("/method/request_body", headers=h, method="PROPFIND", body=b) 
     807        self.assertStatus(200) 
     808        self.assertBody(b) 
    793809         
    794810        # Request a disallowed method 
  • trunk/cherrypy/test/webtest.py

    r1167 r1175  
    324324 
    325325 
     326methods_with_bodies = ("POST", "PUT") 
    326327 
    327328def cleanHeaders(headers, method, body, host, port): 
     
    340341        headers.append(("Host", "%s:%s" % (host, port))) 
    341342     
    342     if method in ("POST", "PUT")
     343    if method in methods_with_bodies
    343344        # Stick in default type and length headers if not present 
    344345        found = False 

Hosted by WebFaction

Log in as guest/cpguest to create tickets