Revision 981d3b0d snf-django-lib/snf_django/lib/api/__init__.py
b/snf-django-lib/snf_django/lib/api/__init__.py | ||
---|---|---|
48 | 48 |
from django.conf import settings |
49 | 49 |
from snf_django.lib.api import faults |
50 | 50 |
|
51 |
import itertools |
|
51 | 52 |
|
52 | 53 |
log = getLogger(__name__) |
53 | 54 |
|
... | ... | |
188 | 189 |
response["Date"] = format_date_time(time()) |
189 | 190 |
|
190 | 191 |
if not response.has_header("Content-Length"): |
191 |
response["Content-Length"] = len(response.content) |
|
192 |
if response._is_string: |
|
193 |
response["Content-Length"] = len(response.content) |
|
194 |
else: |
|
195 |
if not (response.has_header('Content-Type') and |
|
196 |
response['Content-Type'].startswith( |
|
197 |
'multipart/byteranges')): |
|
198 |
# save response content from been consumed if it is an iterator |
|
199 |
response._container, data = itertools.tee(response._container) |
|
200 |
response["Content-Length"] = len(str(data)) |
|
192 | 201 |
|
193 | 202 |
cache.add_never_cache_headers(response) |
194 | 203 |
# Fix Vary and Cache-Control Headers. Issue: #3448 |
Also available in: Unified diff