From 8909e7df1b335b40c0d4578cc55f9deaf52f325e Mon Sep 17 00:00:00 2001 From: Jan-Philip Gehrcke Date: Fri, 14 Oct 2016 16:38:13 +0200 Subject: example/sp-wsgi/sp.py: respond with bytes (enhance WSGI compliance) --- example/sp-wsgi/sp.py | 16 ++++++++-------- src/saml2/httputil.py | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/example/sp-wsgi/sp.py b/example/sp-wsgi/sp.py index 38a737ee..be1e8e68 100755 --- a/example/sp-wsgi/sp.py +++ b/example/sp-wsgi/sp.py @@ -106,21 +106,21 @@ def handle_static(environ, start_response, path): :return: wsgi response for the static file. """ try: - text = open(path).read() + data = open(path, 'rb').read() if path.endswith(".ico"): - resp = Response(text, headers=[('Content-Type', "image/x-icon")]) + resp = Response(data, headers=[('Content-Type', "image/x-icon")]) elif path.endswith(".html"): - resp = Response(text, headers=[('Content-Type', 'text/html')]) + resp = Response(data, headers=[('Content-Type', 'text/html')]) elif path.endswith(".txt"): - resp = Response(text, headers=[('Content-Type', 'text/plain')]) + resp = Response(data, headers=[('Content-Type', 'text/plain')]) elif path.endswith(".css"): - resp = Response(text, headers=[('Content-Type', 'text/css')]) + resp = Response(data, headers=[('Content-Type', 'text/css')]) elif path.endswith(".js"): - resp = Response(text, headers=[('Content-Type', 'text/javascript')]) + resp = Response(data, headers=[('Content-Type', 'text/javascript')]) elif path.endswith(".png"): - resp = Response(text, headers=[('Content-Type', 'image/png')]) + resp = Response(data, headers=[('Content-Type', 'image/png')]) else: - resp = Response(text) + resp = Response(data) except IOError: resp = NotFound() return resp(environ, start_response) diff --git a/src/saml2/httputil.py b/src/saml2/httputil.py index 0901f7b0..0e7f32a6 100644 --- a/src/saml2/httputil.py +++ b/src/saml2/httputil.py @@ -62,6 +62,9 @@ class Response(object): return [mte.render(**argv)] 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] -- cgit v1.2.1