Index: cherrypy/_cpserver.py
===================================================================
--- cherrypy/_cpserver.py	(revision 949)
+++ cherrypy/_cpserver.py	(working copy)
@@ -43,13 +43,16 @@
         self.onStopThreadList = []
     
     def start(self, init_only = False, server_class = _missing,
-                initOnly = None, serverClass = None):
+                initOnly = None, serverClass = None, middleware=list()):
         """Main function. MUST be called from the main thread.
         
         Set initOnly to True to keep this function from blocking.
         Set serverClass to None to skip starting any HTTP server.
         """
         
+        # middleware update
+        self.middleware = middleware
+
         # Read old variable names for backward compatibility
         if initOnly is not None:
             init_only = initOnly
@@ -154,7 +157,12 @@
             on_what = "socket file: %s" % cherrypy.config.get('server.socket_file')
         
         # Instantiate the server.
-        self.httpserver = self.httpserverclass()
+        # middleware update
+        import _cpwsgi
+        if self.httpserverclass == _cpwsgi.WSGIServer:
+            self.httpserver = self.httpserverclass(middleware=self.middleware)
+        else:
+            self.httpserver = self.httpserverclass()
         
         # HTTP servers MUST be started in a new thread, so that the
         # main thread persists to receive KeyboardInterrupt's. This
Index: cherrypy/_cpwsgi.py
===================================================================
--- cherrypy/_cpwsgi.py	(revision 949)
+++ cherrypy/_cpwsgi.py	(working copy)
@@ -9,7 +9,8 @@
 def requestLine(environ):
     """Rebuild first line of the request (e.g. "GET /path HTTP/1.0")."""
     
-    resource = environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '')
+    #resource = environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '')
+    resource = environ.get('PATH_INFO', '')
     if not (resource == "*" or resource.startswith("/")):
         resource = "/" + resource
     
@@ -69,6 +70,7 @@
         request.login = (env('LOGON_USER') or env('REMOTE_USER') or None)
         request.multithread = environ['wsgi.multithread']
         request.multiprocess = environ['wsgi.multiprocess']
+        request.wsgi_environ = environ
         response = request.run(requestLine(environ),
                                translate_headers(environ),
                                environ['wsgi.input'])
@@ -132,6 +134,12 @@
     def parse_request(self):
         try:
             _cpwsgiserver.HTTPRequest.parse_request(self)
+            # ugly patch for middleware compat
+            self.environ['PATH_INFO'] = self.environ.get('SCRIPT_NAME', '')
+            if self.environ['PATH_INFO']:
+                if not self.environ['PATH_INFO'].startswith('*'):
+                    self.environ['PATH_INFO'] = '/' + self.environ['PATH_INFO']
+            self.environ['SCRIPT_NAME'] = ''
         except httptools.MaxSizeExceeded:
             msg = "Request Entity Too Large"
             proto = self.environ.get("SERVER_PROTOCOL", "HTTP/1.0")
@@ -147,11 +155,9 @@
                 # Request header is parsed
                 # We prepare the SizeCheckWrapper for the request body
                 self.rfile.bytes_read = 0
-                path = self.environ["SCRIPT_NAME"]
+                path = self.environ["PATH_INFO"]
                 if path == "*":
                     path = "global"
-                else:
-                    path = "/" + path
                 mbs = int(cherrypy.config.get('server.max_request_body_size',
                                               100 * 1024 * 1024, path=path))
                 self.rfile.maxlen = mbs
@@ -169,7 +175,10 @@
     
     RequestHandlerClass = CPHTTPRequest
     
-    def __init__(self, app=wsgiApp):
+    def __init__(self, app=wsgiApp, middleware=list()):
+        # loop through the list of middlware in reverse order
+        for mw, conf in middleware[::-1]:
+            app = mw(app, **conf)
         conf = cherrypy.config.get
         
         sockFile = cherrypy.config.get('server.socket_file')
