The implementation of calculate_content_length doesn't encode the elements of self.response before using them:
https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/wrappers.py#L926
def calculate_content_length(self):
[...]
return sum(len(x) for x in self.response)
In case self.response is composed of utf-8 encoded unicode strings, this will lead to an invalid return length:
>>> from werkzeug import Response
>>> r = Response()
>>> r.response.append(u'你好')
>>> r.calculate_content_length()
2
>>> len(u'你好'.encode('utf-8'))
6
The easier solution to this would be to use iter_encoded inside calculate_content_length, but would decrease performances given the data would be encoded two time (for calculating content-lenght, then for actualy writing the data)
The implementation of
calculate_content_lengthdoesn't encode the elements ofself.responsebefore using them:https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/wrappers.py#L926
In case self.response is composed of utf-8 encoded unicode strings, this will lead to an invalid return length:
The easier solution to this would be to use
iter_encodedinsidecalculate_content_length, but would decrease performances given the data would be encoded two time (for calculating content-lenght, then for actualy writing the data)