From f9970363a21c0bbcc5183762df38858d8ea86922 Mon Sep 17 00:00:00 2001 From: h3llrais3r Date: Sun, 4 Nov 2018 18:23:25 +0100 Subject: 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 --- cherrypy/lib/httputil.py | 2 +- cherrypy/test/test_encoding.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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') -- cgit v1.2.1 From a9a0a08fa9c03036d6e59bde4abcf281b058dac0 Mon Sep 17 00:00:00 2001 From: h3llrais3r Date: Mon, 5 Nov 2018 19:23:44 +0100 Subject: Fix flake8 error --- cherrypy/lib/httputil.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cherrypy/lib/httputil.py b/cherrypy/lib/httputil.py index 61ac362a..59bcc746 100644 --- a/cherrypy/lib/httputil.py +++ b/cherrypy/lib/httputil.py @@ -518,7 +518,8 @@ class HeaderMap(CaseInsensitiveDict): transmitting on the wire for HTTP. """ for k, v in header_items: - if not isinstance(v, six.string_types) and not isinstance(v, six.binary_type): + 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))) -- cgit v1.2.1 From 7ce80a835f0bc0b75091d1a937a9cfd7c5255821 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 23 Nov 2018 02:15:33 -0600 Subject: Update changelog --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 5f4874b9..d33ae6a1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v17.4.1 +------- + +* :issue:`1738` via :pr:`1755`: Restore support for 'bytes' + in response headers (backport from v18.0.1). + v17.4.0 ------- -- cgit v1.2.1 From 19fc8ae86db7818376f5a9d11359c5f69e8dd747 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 23 Nov 2018 02:26:21 -0600 Subject: Fix test failures on pytest 4 --- cherrypy/test/test_static.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cherrypy/test/test_static.py b/cherrypy/test/test_static.py index 5dc5a144..52f4006f 100644 --- a/cherrypy/test/test_static.py +++ b/cherrypy/test/test_static.py @@ -21,6 +21,10 @@ from cherrypy.test import helper @pytest.fixture def unicode_filesystem(tmpdir): + _check_unicode_filesystem(tmpdir) + + +def _check_unicode_filesystem(tmpdir): filename = tmpdir / ntou('☃', 'utf-8') tmpl = 'File system encoding ({encoding}) cannot support unicode filenames' msg = tmpl.format(encoding=sys.getfilesystemencoding()) @@ -37,7 +41,7 @@ def ensure_unicode_filesystem(): """ tmpdir = py.path.local(tempfile.mkdtemp()) try: - unicode_filesystem(tmpdir) + _check_unicode_filesystem(tmpdir) finally: tmpdir.remove() -- cgit v1.2.1