@@ -80,7 +80,7 @@ def __call__(self, environ, start_response):
80
80
else :
81
81
content = self .content
82
82
83
- response = Response (status = self .code )
83
+ response = Response (response = self . content , status = self .code )
84
84
response .headers .clear ()
85
85
response .headers .extend (self .headers )
86
86
@@ -89,7 +89,6 @@ def __call__(self, environ, start_response):
89
89
# content = gzip.compress(content.encode('utf-8'))
90
90
# response.content_encoding = 'gzip'
91
91
92
- response .data = content
93
92
return response (environ , start_response )
94
93
95
94
def serve_content (self , content , code = 200 , headers = None ):
@@ -101,6 +100,17 @@ def serve_content(self, content, code=200, headers=None):
101
100
:param code: HTTP status code
102
101
:param headers: HTTP headers to be returned
103
102
"""
103
+ if not isinstance (content , (str , bytes , list , tuple )):
104
+ # If content is an iterable which is not known to be a string,
105
+ # bytes, or sequence, it might be something that can only be iterated
106
+ # through once, in which case we need to cache it so it can be reused
107
+ # to handle multiple requests.
108
+ try :
109
+ content = tuple (iter (content ))
110
+ except TypeError :
111
+ # this probably means that content is not iterable, so just go
112
+ # ahead in case it's some type that Response knows how to handle
113
+ pass
104
114
self .content , self .code = (content , code )
105
115
if headers :
106
116
self .headers = headers
0 commit comments