Hi CherryPy Team,
I came across wsgiserver3.py looking for a python WSGI that supported
chunked transfer encoding.
I grabbed it from here:
http://www.cherrypy.org/browser/trunk/cherrypy/wsgiserver/
I'm not sure if that is the latest or not, but seems like it would be.
I came across a couple of small issues when using it.
Firstly, the example code used strings, rather than 'bytes' which
caused errors in wsgi.
Secondly, in trying to track down the problem with the example, I
found a code path where an exception was silently captured, which made
debugging the first problem quite difficult.
Finally, the chunked reader, read method appeared to get in to an
infinite loop.
Attached is a patch that addresses these issues.
Cheers,
Ben
--- wsgiserver3.py?rev=2823&format=raw 2011-07-07 05:10:31.000000000
+1000
+++ wsgiserver3.py 2011-07-28 23:31:48.000000000 +1000
@@ -6,10 +38,10 @@
from cherrypy import wsgiserver
def my_crazy_app(environ, start_response):
- status = '200 OK'
- response_headers = [('Content-type','text/plain')]
+ status = b'200 OK'
+ response_headers = [(b'Content-type',b'text/plain')]
start_response(status, response_headers)
- return ['Hello world!']
+ return [b'Hello world!']
server = wsgiserver.CherryPyWSGIServer(
('0.0.0.0', 8070), my_crazy_app,
@@ -96,7 +128,7 @@
import threading
import time
-from traceback import format_exc
+from traceback import format_exc, print_exc
from urllib.parse import unquote
from urllib.parse import urlparse
from urllib.parse import scheme_chars
@@ -428,6 +460,7 @@
self.buffer = self.buffer[remaining:]
else:
data += self.buffer
+ self.buffer = EMPTY
def readline(self, size=None):
data = EMPTY
@@ -1818,6 +1851,9 @@
if isinstance(chunk, unicodestr):
chunk = chunk.encode('ISO-8859-1')
self.write(chunk)
+ except Exception as e:
+ print("Exception, traceback follows")
+ print_exc()
finally:
if hasattr(response, "close"):
response.close()