diff options
author | Tobias Henkel <tobias.henkel@bmw.de> | 2018-09-04 09:11:01 +0200 |
---|---|---|
committer | Tobias Henkel <tobias.henkel@bmw.de> | 2018-09-04 13:14:15 +0200 |
commit | 802d0205a895fe2a73e9499ea3e572332f113a2a (patch) | |
tree | 60adc6f50cd247a14869174234e002311ca06dde | |
parent | ce51624d23208bbeffddf37de84a3238f64ede7f (diff) | |
download | cherrypy-git-802d0205a895fe2a73e9499ea3e572332f113a2a.tar.gz |
Don't convert bytes headers to str
Don't convert bytes header values using str() as str(b'foo') becomes
"b'foo'". Instead just leave bytes as is like it was prior to v18.0.0.
-rw-r--r-- | cherrypy/lib/httputil.py | 2 | ||||
-rw-r--r-- | cherrypy/test/test_encoding.py | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/cherrypy/lib/httputil.py b/cherrypy/lib/httputil.py index ddafee5b..4ba5be31 100644 --- a/cherrypy/lib/httputil.py +++ b/cherrypy/lib/httputil.py @@ -513,7 +513,7 @@ class HeaderMap(CaseInsensitiveDict): transmitting on the wire for HTTP. """ for k, v in header_items: - if not isinstance(v, str): + if not isinstance(v, str) and not isinstance(v, bytes): v = str(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 44cc08f7..882d7a5b 100644 --- a/cherrypy/test/test_encoding.py +++ b/cherrypy/test/test_encoding.py @@ -49,6 +49,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 @@ -423,3 +425,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') |