summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Philip Gehrcke <jgehrcke@googlemail.com>2016-10-14 16:38:13 +0200
committerJan-Philip Gehrcke <jgehrcke@googlemail.com>2016-10-14 16:38:13 +0200
commit8909e7df1b335b40c0d4578cc55f9deaf52f325e (patch)
treee9e10c0453e94602670c6786984da0f707075090
parentccb842d20b9a4a2334706a180a69a39136f37f08 (diff)
downloadpysaml2-8909e7df1b335b40c0d4578cc55f9deaf52f325e.tar.gz
example/sp-wsgi/sp.py: respond with bytes (enhance WSGI compliance)
-rwxr-xr-xexample/sp-wsgi/sp.py16
-rw-r--r--src/saml2/httputil.py3
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]