summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2018-02-04 14:06:20 -0500
committerMartin van Es <martin@mrvanes.com>2018-06-06 19:35:04 +0200
commit7e30a7b58a27bd794cb1114dd10c44bebee8098f (patch)
tree81fbb0a130a8afed8d33fb54a4045f2dd8317506
parent04b50f498aeb2a3f26419c2cfe2f339bff7b9629 (diff)
downloadcherrypy-git-7e30a7b58a27bd794cb1114dd10c44bebee8098f.tar.gz
Extract function for _flush_body. Use 'consume' to consume an iterator. Use 'iter' to make iterator from iterable.
-rw-r--r--cherrypy/_cprequest.py17
-rwxr-xr-xsetup.py1
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,
diff --git a/setup.py b/setup.py
index 08de7a18..00850598 100755
--- a/setup.py
+++ b/setup.py
@@ -61,6 +61,7 @@ install_requires = [
'six>=1.11.0',
'cheroot>=6.2.4',
'portend>=2.1.1',
+ 'more_itertools',
]
extras_require = {