changeset 13:bb66c9a62be9

unfutz the environ if the resource is not found
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 17 Nov 2011 11:36:19 -0800
parents 89047fd9ea8f
children e07b0f675c17
files wsgintegrate/match.py
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/wsgintegrate/match.py	Thu Nov 17 11:26:33 2011 -0800
+++ b/wsgintegrate/match.py	Thu Nov 17 11:36:19 2011 -0800
@@ -3,6 +3,7 @@
 these are just a sample; you can add arbitrary match objects if desired
 """
 
+from webob import Request
 from webob import exc
 
 class RequestMatch(object):
@@ -53,10 +54,21 @@
     script_name, path_info = match
 
     # fix up the environment for downstream applications
+    _script_name = environ.get('SCRIPT_NAME')
+    _path_info = environ.get('PATH_INFO')
     environ['SCRIPT_NAME'] = script_name
     environ['PATH_INFO'] = path_info
 
-    return self.app(environ, start_response)
+    request = Request(environ)
+    response = request.get_response(self.app)
+
+    # unfutz the environ if the resource is not found
+    if response.status_int == 404:
+        if _script_name is not None:
+            environ['SCRIPT_NAME'] = script_name
+        environ['PATH_INFO'] = _path_info
+
+    return response(environ, start_response)
 
 class MatchMethod(RequestMatch):
   """match based on request method"""
@@ -66,13 +78,13 @@
     if isinstance(methods, basestring):
       methods = methods.split()
     self.methods = set(methods)
-    
+
   def condition(self, environ):
     return environ['REQUEST_METHOD'] in self.methods
 
 class MatchHost(RequestMatch):
   """match based on the host and port"""
-  
+
   def __init__(self, app, host, port=None):
     RequestMatch.__init__(self, app)
     self.host = host