From 9f412cc916908ab95a3ea4dd7852f0dbccc91f8d Mon Sep 17 00:00:00 2001 From: Egor Panfilov Date: Mon, 19 Nov 2018 18:13:38 +0300 Subject: [PATCH 1/2] Fix return format of Response._response --- src/saml2/httputil.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/saml2/httputil.py b/src/saml2/httputil.py index 253ff5709..d0dcd2870 100644 --- a/src/saml2/httputil.py +++ b/src/saml2/httputil.py @@ -55,21 +55,21 @@ def __call__(self, environ, start_response, **kwargs): def _response(self, message="", **argv): if self.template: - return [self.template % message] + message = self.template % message elif self.mako_lookup and self.mako_template: argv["message"] = message mte = self.mako_lookup.get_template(self.mako_template) - return [mte.render(**argv)] + message = mte.render(**argv) + + if isinstance(message, six.string_types): + # Note(JP): A WSGI app should always respond + # with bytes, so at this point the message should + # become encoded instead of passing a text object. + return [message.encode()] + elif isinstance(message, six.binary_type): + return [message] else: - if isinstance(message, six.string_types): - # Note(JP): A WSGI app should always respond - # with bytes, so at this point the message should - # become encoded instead of passing a text object. - return [message] - elif isinstance(message, six.binary_type): - return [message] - else: - return message + return message def add_header(self, ava): """ From aeff86b665062958b265dd4765423bce3eefdb5e Mon Sep 17 00:00:00 2001 From: Ivan Kanakarakis Date: Mon, 19 Nov 2018 20:10:24 +0200 Subject: [PATCH 2/2] Encode response message as utf-8 Signed-off-by: Ivan Kanakarakis --- src/saml2/httputil.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/saml2/httputil.py b/src/saml2/httputil.py index d0dcd2870..dbba7d410 100644 --- a/src/saml2/httputil.py +++ b/src/saml2/httputil.py @@ -62,10 +62,7 @@ def _response(self, message="", **argv): message = mte.render(**argv) if isinstance(message, six.string_types): - # Note(JP): A WSGI app should always respond - # with bytes, so at this point the message should - # become encoded instead of passing a text object. - return [message.encode()] + return [message.encode('utf-8')] elif isinstance(message, six.binary_type): return [message] else: