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

Changeset 1899

Show
Ignore:
Timestamp:
02/21/08 12:43:30
Author:
fumanchu
Message:

Test and potential fix for #790 (Request body of PUT with no Content-Type is parsed incorrectly). It doesn't actually pass yet, but I suspect that's a problem with httplib or something else in between (but I've spent an hour and can't seem to track it down).

Files:

Legend:

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

    r1834 r1899  
    686686        methenv = {'REQUEST_METHOD': "POST"} 
    687687        try: 
     688            # If the headers are missing "Content-Type" then add one 
     689            # with an empty value.  This ensures that FieldStorage 
     690            # won't parse the request body for params if the client 
     691            # didn't provide a "Content-Type" header. 
     692            if 'Content-Type' not in self.headers: 
     693                h = self.headers.copy() 
     694                h['Content-Type'] = 'application/octet-stream' 
     695            else: 
     696                h = self.headers 
     697             
    688698            forms = _cpcgifs.FieldStorage(fp=self.rfile, 
    689                                           headers=self.headers
     699                                          headers=h
    690700                                          environ=methenv, 
    691701                                          keep_blank_values=1) 
  • trunk/cherrypy/test/test_core.py

    r1836 r1899  
    33from cherrypy.test import test 
    44test.prefer_parent_path() 
     5 
     6import os 
     7localDir = os.path.dirname(__file__) 
     8import types 
    59 
    610import cherrypy 
    711from cherrypy import _cptools, tools 
    812from cherrypy.lib import http, static 
    9 import types 
    10  
    11 import os 
    12 localDir = os.path.dirname(__file__) 
     13 
     14 
    1315log_file = os.path.join(localDir, "test.log") 
    1416log_access_file = os.path.join(localDir, "access.log") 
     
    927929        self.assertBody(b) 
    928930         
     931        # Request a PUT method with a file body but no Content-Type. 
     932        # See http://www.cherrypy.org/ticket/790. 
     933        b = "one thing on top of another" 
     934        self.persistent = True 
     935        try: 
     936            conn = self.HTTP_CONN 
     937##            conn.set_debuglevel(10) 
     938            conn.putrequest("PUT", "/method/request_body", skip_host=True) 
     939            conn.putheader("Host", self.HOST) 
     940            conn.putheader('Content-Length', str(len(b))) 
     941            conn.endheaders() 
     942            conn.send(b) 
     943            response = conn.response_class(conn.sock, method="PUT") 
     944            response.begin() 
     945            self.assertEqual(response.status, 200) 
     946            self.body = response.read() 
     947            self.assertBody(b) 
     948        finally: 
     949            self.persistent = False 
     950         
    929951        # Request a PUT method with no body whatsoever (not an empty one). 
    930952        # See http://www.cherrypy.org/ticket/650. 

Hosted by WebFaction

Log in as guest/cpguest to create tickets