Skip to content

Commit d92bfee

Browse files
authored
Merge pull request #369 from jgehrcke/jp/fix-static-file-handler
example/sp-wsgi/sp.py: respond with bytes (enhance WSGI compliance)
2 parents 0075b9c + 8909e7d commit d92bfee

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

example/sp-wsgi/sp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,21 @@ def handle_static(environ, start_response, path):
106106
:return: wsgi response for the static file.
107107
"""
108108
try:
109-
text = open(path).read()
109+
data = open(path, 'rb').read()
110110
if path.endswith(".ico"):
111-
resp = Response(text, headers=[('Content-Type', "image/x-icon")])
111+
resp = Response(data, headers=[('Content-Type', "image/x-icon")])
112112
elif path.endswith(".html"):
113-
resp = Response(text, headers=[('Content-Type', 'text/html')])
113+
resp = Response(data, headers=[('Content-Type', 'text/html')])
114114
elif path.endswith(".txt"):
115-
resp = Response(text, headers=[('Content-Type', 'text/plain')])
115+
resp = Response(data, headers=[('Content-Type', 'text/plain')])
116116
elif path.endswith(".css"):
117-
resp = Response(text, headers=[('Content-Type', 'text/css')])
117+
resp = Response(data, headers=[('Content-Type', 'text/css')])
118118
elif path.endswith(".js"):
119-
resp = Response(text, headers=[('Content-Type', 'text/javascript')])
119+
resp = Response(data, headers=[('Content-Type', 'text/javascript')])
120120
elif path.endswith(".png"):
121-
resp = Response(text, headers=[('Content-Type', 'image/png')])
121+
resp = Response(data, headers=[('Content-Type', 'image/png')])
122122
else:
123-
resp = Response(text)
123+
resp = Response(data)
124124
except IOError:
125125
resp = NotFound()
126126
return resp(environ, start_response)

src/saml2/httputil.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def _response(self, message="", **argv):
6262
return [mte.render(**argv)]
6363
else:
6464
if isinstance(message, six.string_types):
65+
# Note(JP): A WSGI app should always respond
66+
# with bytes, so at this point the message should
67+
# become encoded instead of passing a text object.
6568
return [message]
6669
elif isinstance(message, six.binary_type):
6770
return [message]

0 commit comments

Comments
 (0)