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

Ticket #455: full_patch_on_rev949.diff

  • cherrypy/_cpserver.py

    old new  
    4343        self.onStopThreadList = [] 
    4444     
    4545    def start(self, init_only = False, server_class = _missing, 
    46                 initOnly = None, serverClass = None): 
     46                initOnly = None, serverClass = None, middleware=list()): 
    4747        """Main function. MUST be called from the main thread. 
    4848         
    4949        Set initOnly to True to keep this function from blocking. 
    5050        Set serverClass to None to skip starting any HTTP server. 
    5151        """ 
    5252         
     53        # middleware update 
     54        self.middleware = middleware 
     55 
    5356        # Read old variable names for backward compatibility 
    5457        if initOnly is not None: 
    5558            init_only = initOnly 
     
    154157            on_what = "socket file: %s" % cherrypy.config.get('server.socket_file') 
    155158         
    156159        # Instantiate the server. 
    157         self.httpserver = self.httpserverclass() 
     160        # middleware update 
     161        import _cpwsgi 
     162        if self.httpserverclass == _cpwsgi.WSGIServer: 
     163            self.httpserver = self.httpserverclass(middleware=self.middleware) 
     164        else: 
     165            self.httpserver = self.httpserverclass() 
    158166         
    159167        # HTTP servers MUST be started in a new thread, so that the 
    160168        # main thread persists to receive KeyboardInterrupt's. This 
  • cherrypy/_cpwsgi.py

    old new  
    99def requestLine(environ): 
    1010    """Rebuild first line of the request (e.g. "GET /path HTTP/1.0").""" 
    1111     
    12     resource = environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '') 
     12    #resource = environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '') 
     13    resource = environ.get('PATH_INFO', '') 
    1314    if not (resource == "*" or resource.startswith("/")): 
    1415        resource = "/" + resource 
    1516     
     
    6970        request.login = (env('LOGON_USER') or env('REMOTE_USER') or None) 
    7071        request.multithread = environ['wsgi.multithread'] 
    7172        request.multiprocess = environ['wsgi.multiprocess'] 
     73        request.wsgi_environ = environ 
    7274        response = request.run(requestLine(environ), 
    7375                               translate_headers(environ), 
    7476                               environ['wsgi.input']) 
     
    132134    def parse_request(self): 
    133135        try: 
    134136            _cpwsgiserver.HTTPRequest.parse_request(self) 
     137            # ugly patch for middleware compat 
     138            self.environ['PATH_INFO'] = self.environ.get('SCRIPT_NAME', '') 
     139            if self.environ['PATH_INFO']: 
     140                if not self.environ['PATH_INFO'].startswith('*'): 
     141                    self.environ['PATH_INFO'] = '/' + self.environ['PATH_INFO'] 
     142            self.environ['SCRIPT_NAME'] = '' 
    135143        except httptools.MaxSizeExceeded: 
    136144            msg = "Request Entity Too Large" 
    137145            proto = self.environ.get("SERVER_PROTOCOL", "HTTP/1.0") 
     
    147155                # Request header is parsed 
    148156                # We prepare the SizeCheckWrapper for the request body 
    149157                self.rfile.bytes_read = 0 
    150                 path = self.environ["SCRIPT_NAME"] 
     158                path = self.environ["PATH_INFO"] 
    151159                if path == "*": 
    152160                    path = "global" 
    153                 else: 
    154                     path = "/" + path 
    155161                mbs = int(cherrypy.config.get('server.max_request_body_size', 
    156162                                              100 * 1024 * 1024, path=path)) 
    157163                self.rfile.maxlen = mbs 
     
    169175     
    170176    RequestHandlerClass = CPHTTPRequest 
    171177     
    172     def __init__(self, app=wsgiApp): 
     178    def __init__(self, app=wsgiApp, middleware=list()): 
     179        # loop through the list of middlware in reverse order 
     180        for mw, conf in middleware[::-1]: 
     181            app = mw(app, **conf) 
    173182        conf = cherrypy.config.get 
    174183         
    175184        sockFile = cherrypy.config.get('server.socket_file') 

Hosted by WebFaction

Log in as guest/cpguest to create tickets