Commits

Anonymous committed 0bd34a1

[svn] Small optimization at middleware.py and proper setting of SCRIPT_NAME

Comments (0)

Files changed (1)

toscawidgets/middleware.py

         environ['paste.registry'].register(toscawidgets.framework, framework)
         environ.setdefault('toscawidgets.framework', toscawidgets.framework)
         path_info = environ.get('PATH_INFO', '')
-        for webdir, dirname in registered_directories.get_all():
-            if path_info.startswith(webdir):
-                environ['PATH_INFO'] = path_info.replace(webdir, '')
-                if 'SCRIPT_NAME' in environ:
-                    environ['SCRIPT_NAME'] += webdir
-                return StaticURLParser(dirname)(environ, start_response)
+        if path_info.startswith(registered_directories.prefix):
+            for webdir, dirname in registered_directories.get_all():
+                if path_info.startswith(webdir):
+                    environ['PATH_INFO'] = path_info.replace(webdir, '')
+                    script_name = environ.get('SCRIPT_NAME', '')
+                    environ['SCRIPT_NAME'] = script_name + webdir
+                    return StaticURLParser(dirname)(environ, start_response)
+            return StaticURLParser('').not_found(environ, start_response)
         return self.app(environ, start_response)