Commits

Ning Sun committed 8d69ac0

correct behavior of wsgi.errors

  • Participants
  • Parent commits 6f1aefa

Comments (0)

Files changed (3)

File src/gefr/backends/jetty.py

         start_response = StartResponse()
         data_generator = self.app(environ, start_response)
         status = int(start_response.status)
-        if status >= 500:
-            error_msg = environ['wsgi.errors'].getvalue()
-            response.sendError(status, error_msg)
-            return
-        else:
-            response.setStatus(status)
-            for key,value in start_response.headers.items():
-                response.setHeader(key, value)
-            response.setHeader('Server',  "gefr-%s/%s" % (environ['gefr.backend'], gefr_version))
-            ## generator style
-            writer = response.getWriter()
-            for data in data_generator:
-                writer.println(data)
+        response.setStatus(status)
+        for key,value in start_response.headers.items():
+            response.setHeader(key, value)
+        response.setHeader('Server',  "gefr-%s/%s" % (environ['gefr.backend'], gefr_version))
+        ## generator style
+        writer = response.getWriter()
+        for data in data_generator:
+            writer.println(data)
                 
         baseRequest.setHandled(True)
                 

File src/gefr/backends/netty.py

         response = DefaultHttpResponse(HttpVersion.HTTP_1_1, \
                 HttpResponseStatus.valueOf(status))
         buf = ChannelBuffers.dynamicBuffer(4096)
-        if status >= 500:
-            error_msg = environ['wsgi.errors'].getvalue()
-            buf.writeBytes(error_msg)
-        else:
-            for key,value in start_response.headers.items():
-                response.setHeader(key, value)
-            response.setHeader('Server',  "gefr-%s/%s" % (environ['gefr.backend'], gefr_version))
-            for data in data_generator:
-                buf.writeBytes(data)    
+        for key,value in start_response.headers.items():
+            response.setHeader(key, value)
+        response.setHeader('Server',  "gefr-%s/%s" % (environ['gefr.backend'], gefr_version))
+        for data in data_generator:
+            buf.writeBytes(data)
 
         response.setContent(buf)
         response.setHeader("Content-Length", buf.writerIndex());

File src/gefr/wsgi.py

 ##
 ##
 
+import sys
+
 from org.python.core.util import FileUtil
 from StringIO import StringIO
 
     environ['wsgi.multithread'] = True
     environ['wsgi.multiprocess'] = False
     environ['wsgi.run_once'] = False
-    environ['wsgi.errors'] = StringIO()
+    environ['wsgi.errors'] = sys.err
     return environ
     
 def get_environ_from_servlet_request(request):
     status = start_response.status
     message = start_response.message
 
-    output = ''.join(body) if int(status) < 500 else environ['wsgi.errors'].getvalue()
+    output = ''.join(body)
     output = unicode(output, encoding='utf8')
 
     first_line = " ".join(["HTTP/1.1", status, message])