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

Changeset 1520

Show
Ignore:
Timestamp:
12/11/06 15:18:07
Author:
fumanchu
Message:

Added the WSGI server from CP 3 to the distro. Enable it via the config option: server.class = 'cherrypy._cpwsgi.CPWSGIServer3'.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-2.x/cherrypy/_cpwsgi.py

    r1509 r1520  
    33import sys 
    44import cherrypy 
    5 from cherrypy import _cputil, _cpwsgiserver 
     5from cherrypy import _cputil, _cpwsgiserver, _cpwsgiserver3 
    66from cherrypy.lib import httptools 
    77 
     
    160160        else: 
    161161            if self.ready: 
    162                 # Request header is parsed 
    163                 script_name = self.environ.get('SCRIPT_NAME', '') 
    164                 path_info = self.environ.get('PATH_INFO', '') 
    165                 path = (script_name + path_info) 
    166                 if path == "*": 
    167                     path = "global" 
    168                  
    169162                if isinstance(self.rfile, httptools.SizeCheckWrapper): 
    170163                    # Unwrap the rfile 
     
    208201                   ) 
    209202 
     203 
     204#                            Server3 components                            # 
     205 
     206 
     207class CPHTTPRequest3(_cpwsgiserver3.HTTPRequest): 
     208     
     209    def parse_request(self): 
     210        mhs = int(cherrypy.config.get('server.max_request_header_size', 
     211                                      500 * 1024)) 
     212        if mhs > 0: 
     213            self.rfile = httptools.SizeCheckWrapper(self.rfile, mhs) 
     214         
     215        try: 
     216            _cpwsgiserver3.HTTPRequest.parse_request(self) 
     217        except httptools.MaxSizeExceeded: 
     218            self.simple_response("413 Request Entity Too Large") 
     219            cherrypy.log(traceback=True) 
     220        else: 
     221            if self.ready: 
     222                if isinstance(self.rfile, httptools.SizeCheckWrapper): 
     223                    # Unwrap the rfile 
     224                    self.rfile = self.rfile.rfile 
     225                self.environ["wsgi.input"] = self.rfile 
     226     
     227    def decode_chunked(self): 
     228        """Decode the 'chunked' transfer coding.""" 
     229        if isinstance(self.rfile, httptools.SizeCheckWrapper): 
     230            self.rfile = self.rfile.rfile 
     231        mbs = int(cherrypy.config.get('server.max_request_body_size', 
     232                                      100 * 1024 * 1024)) 
     233        if mbs > 0: 
     234            self.rfile = httptools.SizeCheckWrapper(self.rfile, mbs) 
     235        try: 
     236            return _cpwsgiserver3.HTTPRequest.decode_chunked(self) 
     237        except httptools.MaxSizeExceeded: 
     238            self.simple_response("413 Request Entity Too Large") 
     239            cherrypy.log(traceback=True) 
     240            return False 
     241 
     242 
     243class CPHTTPConnection3(_cpwsgiserver3.HTTPConnection): 
     244     
     245    RequestHandlerClass = CPHTTPRequest3 
     246 
     247 
     248class CPWSGIServer3(_cpwsgiserver3.CherryPyWSGIServer): 
     249    """Wrapper for _cpwsgiserver3.CherryPyWSGIServer. 
     250     
     251    wsgiserver has been designed to not reference CherryPy in any way, 
     252    so that it can be used in other frameworks and applications. Therefore, 
     253    we wrap it here, so we can set our own mount points from cherrypy.tree. 
     254    """ 
     255     
     256    ConnectionClass = CPHTTPConnection3 
     257     
     258    def __init__(self): 
     259        conf = cherrypy.config.get 
     260         
     261        sockFile = cherrypy.config.get('server.socket_file') 
     262        if sockFile: 
     263            bind_addr = sockFile 
     264        else: 
     265            bind_addr = (conf("server.socket_host"), conf("server.socket_port")) 
     266         
     267        pts = cherrypy.tree.mount_points 
     268        if pts: 
     269            apps = [(base, wsgiApp) for base in pts.keys()] 
     270        else: 
     271            apps = [("", wsgiApp)] 
     272         
     273        s = _cpwsgiserver3.CherryPyWSGIServer 
     274        s.__init__(self, bind_addr, apps, 
     275                   conf("server.thread_pool"), 
     276                   conf("server.socket_host"), 
     277                   request_queue_size = conf('server.socket_queue_size'), 
     278                   timeout = conf('server.socket_timeout'), 
     279                   ) 
     280         
     281        self.protocol = conf("server.protocol_version") 
     282        self.ssl_certificate = conf("server.ssl_certificate") 
     283        self.ssl_private_key = conf("server.ssl_private_key") 
     284 
  • branches/cherrypy-2.x/cherrypy/test/test.py

    r1512 r1520  
    6868class CommandLineParser(object): 
    6969    available_servers = {'wsgi': "cherrypy._cpwsgi.WSGIServer", 
     70                         'wsgi3': "cherrypy._cpwsgi.CPWSGIServer3", 
    7071                         'modpy': "modpy", 
    7172                         } 
  • branches/cherrypy-2.x/cherrypy/test/test_core.py

    r1498 r1520  
    858858        self.getPage("/", headers=[('From', "x" * 500)]) 
    859859        self.assertStatus(413) 
    860         self.assertInBody("Request Entity Too Large") 
    861860         
    862861        # Test for http://www.cherrypy.org/ticket/421 
     
    887886        self.getPage('/upload', h, "POST", b) 
    888887        self.assertStatus(413) 
    889         self.assertInBody("Request Entity Too Large") 
    890888     
    891889    def testEmptyThreadlocals(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets