summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorh3llrais3r <pooh_beer_1@hotmail.com>2018-11-04 18:23:25 +0100
committerh3llrais3r <pooh_beer_1@hotmail.com>2018-11-04 18:23:25 +0100
commitf9970363a21c0bbcc5183762df38858d8ea86922 (patch)
tree54c91ed79b58e94f4e39cc8c2b05e490f532e29c
parent545a4d24fb93c95507bba992ba8559c07b9adacd (diff)
downloadcherrypy-git-f9970363a21c0bbcc5183762df38858d8ea86922.tar.gz
Don't convert bytes headers to str
Backport https://github.com/cherrypy/cherrypy/pull/1736 Also fixes https://github.com/Lawouach/WebSocket-for-Python/pull/252
-rw-r--r--cherrypy/lib/httputil.py2
-rw-r--r--cherrypy/test/test_encoding.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/cherrypy/lib/httputil.py b/cherrypy/lib/httputil.py
index b68d8dd5..61ac362a 100644
--- a/cherrypy/lib/httputil.py
+++ b/cherrypy/lib/httputil.py
@@ -518,7 +518,7 @@ class HeaderMap(CaseInsensitiveDict):
transmitting on the wire for HTTP.
"""
for k, v in header_items:
- if not isinstance(v, six.string_types):
+ if not isinstance(v, six.string_types) and not isinstance(v, six.binary_type):
v = six.text_type(v)
yield tuple(map(cls.encode_header_item, (k, v)))
diff --git a/cherrypy/test/test_encoding.py b/cherrypy/test/test_encoding.py
index ab24ab93..26b0aa18 100644
--- a/cherrypy/test/test_encoding.py
+++ b/cherrypy/test/test_encoding.py
@@ -50,6 +50,8 @@ class EncodingTests(helper.CPWebCase):
cherrypy.response.cookie['candy']['domain'] = 'cherrypy.org'
cherrypy.response.headers[
'Some-Header'] = 'My d\xc3\xb6g has fleas'
+ cherrypy.response.headers[
+ 'Bytes-Header'] = b'Bytes given header'
return 'Any content'
@cherrypy.expose
@@ -424,3 +426,8 @@ class EncodingTests(helper.CPWebCase):
def test_UnicodeHeaders(self):
self.getPage('/cookies_and_headers')
self.assertBody('Any content')
+
+ def test_BytesHeaders(self):
+ self.getPage('/cookies_and_headers')
+ self.assertBody('Any content')
+ self.assertHeader('Bytes-Header', 'Bytes given header')