moksha/middleware/connector.py | 17 ++++++++++++++++-
moksha/middleware/extensionpoint.py | 16 +++++++++++++++-
moksha/middleware/middleware.py | 23 +++++++++++++++++++----
3 files changed, 50 insertions(+), 6 deletions(-)
New commits:
commit 84844a1437c216976d6701b0fe818c30b5cf9b9b
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Tue Apr 14 14:41:53 2009 -0400
strip the SCRIPT_NAME environ variable so we can work when mounted on any path
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py
index eca14b2..f940b94 100644
--- a/moksha/middleware/connector.py
+++ b/moksha/middleware/connector.py
@@ -48,13 +48,28 @@ class MokshaConnectorMiddleware(object):
self.application = application
self.load_connectors()
+ def strip_script(self, environ, path):
+ # Strips the script portion of a url path so the middleware works even
+ # when mounted under a path other than root
+ if path.startswith('/') and 'SCRIPT_NAME' in environ:
+ prefix = environ.get('SCRIPT_NAME')
+ if prefix.endswith('/'):
+ prefix = prefix[:-1]
+
+ if path.startswith(prefix):
+ path = path[len(prefix):]
+
+ return path
+
def __call__(self, environ, start_response):
request = Request(environ)
- if request.path.startswith('/moksha_connector'):
+ path = self.strip_script(environ, request.path)
+ if path.startswith('/moksha_connector'):
s = request.path.split('/')[2:]
+
# since keys are not unique we need to condense them
# into an actual dictionary with multiple entries becoming lists
p = request.params
diff --git a/moksha/middleware/extensionpoint.py b/moksha/middleware/extensionpoint.py
index a88250d..081e2b9 100644
--- a/moksha/middleware/extensionpoint.py
+++ b/moksha/middleware/extensionpoint.py
@@ -187,11 +187,25 @@ class MokshaExtensionPointMiddleware(object):
s = '[' + ','.join(value) + ']'
self.__extension_cache[key] = s
+ def strip_script(self, environ, path):
+ # Strips the script portion of a url path so the middleware works even
+ # when mounted under a path other than root
+ if path.startswith('/') and 'SCRIPT_NAME' in environ:
+ prefix = environ.get('SCRIPT_NAME')
+ if prefix.endswith('/'):
+ prefix = prefix[:-1]
+
+ if path.startswith(prefix):
+ path = path[len(prefix):]
+
+ return path
+
def __call__(self, environ, start_response):
request = Request(environ)
- if request.path.startswith('/moksha_extension_point'):
+ path = self.strip_script(environ, request.path)
+ if path.startswith('/moksha_extension_point'):
exttype = request.params.get('exttype')
if not exttype:
response = Response('')
diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py
index 0438e71..bdb03f1 100644
--- a/moksha/middleware/middleware.py
+++ b/moksha/middleware/middleware.py
@@ -70,13 +70,28 @@ class MokshaMiddleware(object):
moksha.feed_storage = Shove(config['feed_cache'], compress=True)
moksha.feed_cache = Cache(moksha.feed_storage)
+ def strip_script(self, environ, path):
+ # Strips the script portion of a url path so the middleware works even
+ # when mounted under a path other than root
+ if path.startswith('/') and 'SCRIPT_NAME' in environ:
+ prefix = environ.get('SCRIPT_NAME')
+ if prefix.endswith('/'):
+ prefix = prefix[:-1]
+
+ if path.startswith(prefix):
+ path = path[len(prefix):]
+
+ return path
+
def __call__(self, environ, start_response):
self.register_stomp(environ)
request = Request(environ)
- if request.path.startswith('/apps/') or \
- request.path.startswith('/widget') or \
- request.path.startswith('/docs/') or \
- request.path.startswith('/moksha_admin/'):
+
+ path = self.strip_script(environ, request.path)
+ if path.startswith('/apps/') or \
+ path.startswith('/widget') or \
+ path.startswith('/docs/') or \
+ path.startswith('/moksha_admin/'):
response = request.get_response(self.mokshaapp)
else:
response = request.get_response(self.application)
Show replies by date