diff --git a/CHANGES.rst b/CHANGES.rst index edac84affb..bf71854c4b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -38,6 +38,7 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst For details, see `#1202 `_. +- Small optimization when encoding the response body. 5.9 (2023-11-24) ---------------- diff --git a/src/ZPublisher/HTTPResponse.py b/src/ZPublisher/HTTPResponse.py index 264a488a03..9967cd9b8f 100644 --- a/src/ZPublisher/HTTPResponse.py +++ b/src/ZPublisher/HTTPResponse.py @@ -552,7 +552,9 @@ def setBody(self, body, title='', is_error=False, lock=None): except (TypeError, UnicodeError): pass if not isinstance(body, bytes): - body = self._encode_unicode(str(body)) + if not isinstance(body, str): + body = str(body) + body = self._encode_unicode(body) # At this point body is always binary b_len = len(body)