Ticket #455: full_patch_on_rev949.diff
-
cherrypy/_cpserver.py
old new 43 43 self.onStopThreadList = [] 44 44 45 45 def start(self, init_only = False, server_class = _missing, 46 initOnly = None, serverClass = None ):46 initOnly = None, serverClass = None, middleware=list()): 47 47 """Main function. MUST be called from the main thread. 48 48 49 49 Set initOnly to True to keep this function from blocking. 50 50 Set serverClass to None to skip starting any HTTP server. 51 51 """ 52 52 53 # middleware update 54 self.middleware = middleware 55 53 56 # Read old variable names for backward compatibility 54 57 if initOnly is not None: 55 58 init_only = initOnly … … 154 157 on_what = "socket file: %s" % cherrypy.config.get('server.socket_file') 155 158 156 159 # 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() 158 166 159 167 # HTTP servers MUST be started in a new thread, so that the 160 168 # main thread persists to receive KeyboardInterrupt's. This -
cherrypy/_cpwsgi.py
old new 9 9 def requestLine(environ): 10 10 """Rebuild first line of the request (e.g. "GET /path HTTP/1.0").""" 11 11 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', '') 13 14 if not (resource == "*" or resource.startswith("/")): 14 15 resource = "/" + resource 15 16 … … 69 70 request.login = (env('LOGON_USER') or env('REMOTE_USER') or None) 70 71 request.multithread = environ['wsgi.multithread'] 71 72 request.multiprocess = environ['wsgi.multiprocess'] 73 request.wsgi_environ = environ 72 74 response = request.run(requestLine(environ), 73 75 translate_headers(environ), 74 76 environ['wsgi.input']) … … 132 134 def parse_request(self): 133 135 try: 134 136 _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'] = '' 135 143 except httptools.MaxSizeExceeded: 136 144 msg = "Request Entity Too Large" 137 145 proto = self.environ.get("SERVER_PROTOCOL", "HTTP/1.0") … … 147 155 # Request header is parsed 148 156 # We prepare the SizeCheckWrapper for the request body 149 157 self.rfile.bytes_read = 0 150 path = self.environ[" SCRIPT_NAME"]158 path = self.environ["PATH_INFO"] 151 159 if path == "*": 152 160 path = "global" 153 else:154 path = "/" + path155 161 mbs = int(cherrypy.config.get('server.max_request_body_size', 156 162 100 * 1024 * 1024, path=path)) 157 163 self.rfile.maxlen = mbs … … 169 175 170 176 RequestHandlerClass = CPHTTPRequest 171 177 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) 173 182 conf = cherrypy.config.get 174 183 175 184 sockFile = cherrypy.config.get('server.socket_file')

