summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Hedberg <roland@catalogix.se>2017-10-11 08:37:08 +0200
committerGitHub <noreply@github.com>2017-10-11 08:37:08 +0200
commitd92bfee0ccd2f970afb22c9a6a087cab8cac4628 (patch)
treed724537d8fb9db57d7473c856781469b649651e7
parent0075b9ca0d711e81e747f8313afcd8642210fd8f (diff)
parent8909e7df1b335b40c0d4578cc55f9deaf52f325e (diff)
downloadpysaml2-d92bfee0ccd2f970afb22c9a6a087cab8cac4628.tar.gz
Merge pull request #369 from jgehrcke/jp/fix-static-file-handler
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]