From a6a186891e59eb82e0608a98ae924ba7fc6d2f66 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Tue, 20 Sep 2016 15:41:25 -0700 Subject: [PATCH] wbrequestresponse: text response: calculate Content-Length from encoded utf-8 bytes, not the original text --- pywb/framework/wbrequestresponse.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pywb/framework/wbrequestresponse.py b/pywb/framework/wbrequestresponse.py index 36afff40..4d547989 100644 --- a/pywb/framework/wbrequestresponse.py +++ b/pywb/framework/wbrequestresponse.py @@ -239,11 +239,12 @@ class WbResponse(object): @staticmethod def text_response(text, status='200 OK', content_type='text/plain; charset=utf-8'): + encoded_text = text.encode('utf-8') status_headers = StatusAndHeaders(status, [('Content-Type', content_type), - ('Content-Length', str(len(text)))]) + ('Content-Length', str(len(encoded_text)))]) - return WbResponse(status_headers, value=[text.encode('utf-8')]) + return WbResponse(status_headers, value=[encoded_text]) @staticmethod def redir_response(location, status='302 Redirect', headers=None):