cyclone
cyclone copied to clipboard
Fix bytes/string issue when using chunked transfer encoding
When chunked transfer encoding is used (the default behavior for responses to HTTP 1.1 requests) an exception gets raised because transform_chunk returns an str, which then gets appended to headers in flush, which is a bytestring, so you get a traceback like this:
File "/home/marcus/......../twisted/internet/defer.py", line 654, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/home/marcus/src/cyclone/cyclone/web.py", line 1159, in _execute_failure
return self._handle_request_exception(err)
File "/home/marcus/src/cyclone/cyclone/web.py", line 1211, in _handle_request_exception
self.send_error(500, exception=e)
File "/home/marcus/src/cyclone/cyclone/web.py", line 766, in send_error
self.finish()
File "/home/marcus/src/cyclone/cyclone/web.py", line 746, in finish
self.flush(include_footers=True)
File "/home/marcus/src/cyclone/cyclone/web.py", line 708, in flush
self.request.write(headers + chunk)
builtins.TypeError: can't concat str to bytes
There was also another bug where ChunkedTransferEncoding.transform_chunk would include b' prefixes on the chunk size and chunk contents.