summaryrefslogtreecommitdiff
path: root/flup
diff options
context:
space:
mode:
authorAllan Saddi <allan@saddi.com>2005-05-31 22:37:04 +0000
committerAllan Saddi <allan@saddi.com>2005-05-31 22:37:04 +0000
commitcbb20d0bd7a37b755ea6589e3a5010b6143bf8a7 (patch)
tree30277dd6a0a8a7629036ae9eb9f0101d5d455a07 /flup
parent2d7095a8ae73f3af6e8f05b62c47fa60e6c97bbc (diff)
downloadflup-cbb20d0bd7a37b755ea6589e3a5010b6143bf8a7.tar.gz
Take scriptName from the WSGI_SCRIPT_NAME environment variable
passed from the web server, if present. Check if scriptName is None, and if so, don't modify SCRIPT_NAME & PATH_INFO. For better compatibility with cgi2scgi. (scgi_base)
Diffstat (limited to 'flup')
-rw-r--r--flup/server/ajp_base.py23
-rw-r--r--flup/server/scgi_base.py11
2 files changed, 24 insertions, 10 deletions
diff --git a/flup/server/ajp_base.py b/flup/server/ajp_base.py
index e6c7aee..76c2534 100644
--- a/flup/server/ajp_base.py
+++ b/flup/server/ajp_base.py
@@ -471,9 +471,7 @@ class Request(object):
def __init__(self, conn):
self._conn = conn
- self.environ = {
- 'SCRIPT_NAME': conn.server.scriptName
- }
+ self.environ = {}
self.input = InputStream(conn)
self._headersSent = False
@@ -520,12 +518,6 @@ class Request(object):
def setRequestURI(self, value):
self.environ['REQUEST_URI'] = value
- scriptName = self._conn.server.scriptName
- if not value.startswith(scriptName):
- self.logger.warning('scriptName does not match request URI')
-
- self.environ['PATH_INFO'] = value[len(scriptName):]
-
def setRemoteAddr(self, value):
self.environ['REMOTE_ADDR'] = value
@@ -847,6 +839,8 @@ class BaseAJPServer(object):
else:
environ['wsgi.url_scheme'] = 'http'
+ self._sanitizeEnv(environ)
+
headers_set = []
headers_sent = []
result = None
@@ -916,6 +910,17 @@ class BaseAJPServer(object):
if not self.multithreaded:
self._appLock.release()
+ def _sanitizeEnv(self, environ):
+ """Fill-in/deduce missing values in environ."""
+ # Namely SCRIPT_NAME/PATH_INFO
+ value = environ['REQUEST_URI']
+ scriptName = environ.get('WSGI_SCRIPT_NAME', self.scriptName)
+ if not value.startswith(scriptName):
+ self.logger.warning('scriptName does not match request URI')
+
+ environ['PATH_INFO'] = value[len(scriptName):]
+ environ['SCRIPT_NAME'] = scriptName
+
def error(self, request):
"""
Override to provide custom error handling. Ideally, however,
diff --git a/flup/server/scgi_base.py b/flup/server/scgi_base.py
index be8dede..0aec77a 100644
--- a/flup/server/scgi_base.py
+++ b/flup/server/scgi_base.py
@@ -443,11 +443,20 @@ class BaseSCGIServer(object):
def _sanitizeEnv(self, environ):
"""Fill-in/deduce missing values in environ."""
# Namely SCRIPT_NAME/PATH_INFO
+ scriptName = environ.get('WSGI_SCRIPT_NAME')
+ if scriptName is None:
+ scriptName = self.scriptName
+ elif scriptName.lower() == 'none':
+ scriptName = None
+
+ if scriptName is None:
+ # Do nothing (most likely coming from cgi2scgi)
+ return
+
value = environ['SCRIPT_NAME']
# Pull PATH_INFO from environ, if it exists. (cgi2scgi actually
# passes it in.)
value += environ.get('PATH_INFO', '')
- scriptName = self.scriptName
if not value.startswith(scriptName):
self.logger.warning('scriptName does not match request URI')