[z3-checkins] r10721 - z3/modzope/trunk/src/modzope

philikon at codespeak.net philikon at codespeak.net
Sat Apr 16 10:25:49 MEST 2005


Author: philikon
Date: Sat Apr 16 10:25:49 2005
New Revision: 10721

Modified:
   z3/modzope/trunk/src/modzope/wsgi.py
Log:
sort out problems with the environment; slowly getting there


Modified: z3/modzope/trunk/src/modzope/wsgi.py
==============================================================================
--- z3/modzope/trunk/src/modzope/wsgi.py	(original)
+++ z3/modzope/trunk/src/modzope/wsgi.py	Sat Apr 16 10:25:49 2005
@@ -140,8 +140,34 @@
         # PEP333 says you shouldn't add line separators
         self.write(''.join(seq))
 
+def envFromApache(req):
+    """Fetch environment from Apache request.
+
+    Works like mod_python.apache.build_cgi_env, but fits better to our
+    use."""
+    req.add_common_vars()
+    env = req.subprocess_env.copy()
+    # zope.publisher needs this
+    # maybe use req.parsed_uri[apache.URI_PATH]?
+    env['PATH_INFO'] = req.uri
+
+    if len(req.path_info) > 0:
+        env["SCRIPT_NAME"] = req.uri[:-len(req.path_info)]
+    else:
+        env["SCRIPT_NAME"] = req.uri
+
+    if req.headers_in.has_key("authorization"):
+        env["HTTP_AUTHORIZATION"] = req.headers_in["authorization"]
+
+    return env
+
+
 class ModPythonHandler(BaseCGIHandler):
 
+    # we're not run as a CGI script, so don't take over os.environ as
+    # request variables
+    os_environ = {}
+
     def __init__(self, request):
         from mod_python import apache
         options = request.get_options()
@@ -162,7 +188,7 @@
             threaded = mpm_query(apache.AP_MPMQ_IS_THREADED)
             forked = mpm_query(apache.AP_MPMQ_IS_FORKED)
 
-        apache_env = apache.build_cgi_env(request)
+        apache_env = envFromApache(request)
 
         BaseCGIHandler.__init__(
             self, stdin=ModPythonInputStream(request), stdout=None,


More information about the z3-checkins mailing list