diff options
-rw-r--r-- | cherrypy/_cprequest.py | 17 | ||||
-rwxr-xr-x | setup.py | 1 |
2 files changed, 13 insertions, 5 deletions
diff --git a/cherrypy/_cprequest.py b/cherrypy/_cprequest.py index 17ca93ec..bde09891 100644 --- a/cherrypy/_cprequest.py +++ b/cherrypy/_cprequest.py @@ -2,9 +2,12 @@ import sys import time import uuid + import six from six.moves.http_cookies import SimpleCookie, CookieError +from more_itertools.recipes import consume + import cherrypy from cherrypy._cpcompat import text_or_bytes, ntob from cherrypy import _cpreqbody @@ -879,6 +882,14 @@ class Response(object): self.body = newbody return newbody + def _flush_body(self): + """ + Discard self.body but consume any generator such that + any finalization can occur, such as is required by + caching.tee_output(). + """ + consume(iter(self.body)) + def finalize(self): """Transform headers (and cookies) into self.header_list. (Core)""" try: @@ -903,11 +914,7 @@ class Response(object): # and 304 (not modified) responses MUST NOT # include a message-body." dict.pop(headers, 'Content-Length', None) - # self.body is a generator object that must be yielded - # for _caching.tee_output() to finish it's job and - # remove orphaned threading._Event object from cache - for i in self.body: - pass + self._flush_body() self.body = b'' else: # Responses which are not streamed should have a Content-Length, @@ -61,6 +61,7 @@ install_requires = [ 'six>=1.11.0', 'cheroot>=6.2.4', 'portend>=2.1.1', + 'more_itertools', ] extras_require = { |