[Checkins] SVN: zope.app.wsgi/trunk/ Set the WSGI environment's ``REMOTE_USER`` item (if not already set)
Jim Fulton
jim at zope.com
Tue Jan 10 23:06:02 UTC 2012
Log message for revision 124018:
Set the WSGI environment's ``REMOTE_USER`` item (if not already set)
with the Zope principal label. (This is the same data set in
the ``wsgi.logging_info`` environment item.)
This change allows user info to be used by `paste.translogger
<http://pythonpaste.org/modules/translogger.html>`_ middleware (or
any similar middleware that uses ``REMOTE_USER``), which provides
access logging.
Changed:
U zope.app.wsgi/trunk/CHANGES.txt
U zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt
U zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
-=-
Modified: zope.app.wsgi/trunk/CHANGES.txt
===================================================================
--- zope.app.wsgi/trunk/CHANGES.txt 2012-01-10 20:43:34 UTC (rev 124017)
+++ zope.app.wsgi/trunk/CHANGES.txt 2012-01-10 23:06:01 UTC (rev 124018)
@@ -3,12 +3,19 @@
=======
-3.13.1 (unreleased)
+3.14.0 (2012-01-10)
-------------------
-- Nothing changed yet.
+- Set the WSGI environment's ``REMOTE_USER`` item (if not already set)
+ with the Zope principal label. (This is the same data set in
+ the ``wsgi.logging_info`` environment item.)
+ This change allows user info to be used by `paste.translogger
+ <http://pythonpaste.org/modules/translogger.html>`_ middleware (or
+ any similar middleware that uses ``REMOTE_USER``), which provides
+ access logging.
+
3.13.0 (2011-03-15)
-------------------
Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt 2012-01-10 20:43:34 UTC (rev 124017)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt 2012-01-10 23:06:01 UTC (rev 124018)
@@ -104,11 +104,30 @@
`ILoggingInfo`. Out-of-the-box, `zope.publisher` registers a base
adapter that returns the principal id as value::
- >>> print environ
- {'wsgi.input': <cStringIO.StringI object at ...>,
- 'wsgi.logging_info': 'zope.anybody', 'PATH_INFO': '/'}
+ >>> from pprint import pprint
+ >>> pprint(environ)
+ {'PATH_INFO': '/',
+ 'REMOTE_USER': 'zope.anybody',
+ 'wsgi.input': <cStringIO.StringI object at ...>,
+ 'wsgi.logging_info': 'zope.anybody'}
+.. edge case
+ If remote user is already set, don't update it:
+
+ >>> environ = {
+ ... 'PATH_INFO': '/',
+ ... 'REMOTE_USER': 'someoneelse',
+ ... 'wsgi.input': cStringIO.StringIO('')}
+
+ >>> _ = list(app(environ, start_response))
+ >>> pprint(environ)
+ {'PATH_INFO': '/',
+ 'REMOTE_USER': 'someoneelse',
+ 'wsgi.input': <cStringIO.StringI object at ...>,
+ 'wsgi.logging_info': 'zope.anybody'}
+
+
Creating A WSGI Application
---------------------------
Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py 2012-01-10 20:43:34 UTC (rev 124017)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py 2012-01-10 23:06:01 UTC (rev 124018)
@@ -65,6 +65,8 @@
else:
message = logging_info.getLogMessage()
environ['wsgi.logging_info'] = message
+ if 'REMOTE_USER' not in environ:
+ environ['REMOTE_USER'] = message
# Start the WSGI server response
start_response(response.getStatusString(), response.getHeaders())
More information about the checkins
mailing list