Commits

Robert Brewer committed d43dd87

1. Set cpg.request.login in _cpwsgi.wsgiApp.
2. Fixed ticket #169.
3. Fixed WSGI server sockets for *nix.

Comments (0)

Files changed (4)

cherrypy/_cphttptools.py

     body = func(*(virtualPathList + cpg.request.paramList),
                 **(cpg.request.paramMap))
     
+    cpg.response.body = body = iterable(body)
+    return body
+
+def iterable(body):
     # build a uniform return type (iterable)
     if isinstance(body, types.FileType):
         body = fileGenerator(body)
         body = [body]
     elif body is None:
         body = [""]
-    cpg.response.body = body
     return body
 
 def checkStatus():

cherrypy/_cpwsgi.py

             translatedHeader = cgiName[5:].replace("_", "-")
             yield translatedHeader, environ[cgiName]
 
+
 class NullWriter(object):
     
     def write(self, data):
         sys.stderr = NullWriter()
     
     try:
+        # LOGON_USER is served by IIS, and is the name of the
+        # user after having been mapped to a local account.
+        # Both IIS and Apache set REMOTE_USER, when possible.
+        cpg.request.login = (environ.get('LOGON_USER')
+                             or environ.get('REMOTE_USER') or None)
         cpg.request.method = environ['REQUEST_METHOD']
         cpg.request.multithread = environ['wsgi.multithread']
         cpg.request.multiprocess = environ['wsgi.multiprocess']

cherrypy/_cpwsgiserver.py

         '''
         # We don't have to trap KeyboardInterrupt or SystemExit here,
         # because _cpserver already does so, calling self.stop() for us.
+        # If you're using this server with another framework, you should
+        # trap those exceptions in whatever code block calls start().
         self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
+        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         self.socket.bind(self.bind_addr)
         self.socket.settimeout(1)
         self.socket.listen(5)

cherrypy/lib/filter/sessionfilter.py

     if not sessionId:
         sessionId = generateSessionId()
         cpg.request.sessionMap = {'_sessionId': sessionId}
-    
-    cpg.response.simpleCookie[cookieName] = sessionId
-    cpg.response.simpleCookie[cookieName]['path'] = '/'
-    cpg.response.simpleCookie[cookieName]['version'] = 1
+        
+        cpg.response.simpleCookie[cookieName] = sessionId
+        cpg.response.simpleCookie[cookieName]['path'] = '/'
+        cpg.response.simpleCookie[cookieName]['version'] = 1
 
 def generateSessionId():
     s = ''.join([random.choice(alphanum) for i in xrange(50)])
         _cputil.getSpecialFunction('_cpCleanUpOldSessions')()
 
 def saveSessionData():
-    cookieName = cpg.config.get('session.cookieName')
-    sessionId = cpg.response.simpleCookie[cookieName].value
+    sessionId = cpg.request.sessionMap['_sessionId']
     timeout = cpg.config.get('session.timeout')
     expire = (time.time() + (timeout * 60))
     savefunc = _cputil.getSpecialFunction('_cpSaveSessionData')