Revision 4d244f4a

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

  
......
187 188
        response["Date"] = format_date_time(time())
188 189

  
189 190
    if not response.has_header("Content-Length"):
190
        response["Content-Length"] = len(response.content)
191
        if response._is_string:
192
            response["Content-Length"] = len(response.content)
193
        else:
194
            # save response content from been consumed if it is an iterator
195
            response._container, data = itertools.tee(response._container)
196
            response["Content-Length"] = len(str(data))
191 197

  
192 198
    cache.add_never_cache_headers(response)
193 199
    # Fix Vary and Cache-Control Headers. Issue: #3448
b/snf-pithos-app/pithos/api/util.py
1037 1037

  
1038 1038

  
1039 1039
def update_response_headers(request, response):
1040
    if (not response.has_header('Content-Length') and
1041
        not (response.has_header('Content-Type') and
1042
             response['Content-Type'].startswith('multipart/byteranges'))):
1043
        response['Content-Length'] = len(response.content)
1044

  
1045 1040
    # URL-encode unicode in headers.
1046 1041
    meta = response.items()
1047 1042
    for k, v in meta:

Also available in: Unified diff