From 4c63b7de77196057a467addceb97a42ab93bb404 Mon Sep 17 00:00:00 2001 From: "James M. Allen" Date: Thu, 20 Sep 2018 14:01:59 -0400 Subject: [PATCH] Use iter_raw when making headers h2-safe to preserve original headers --- hyper/http20/util.py | 7 +++++-- test/test_hyper.py | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hyper/http20/util.py b/hyper/http20/util.py index ca5547d0..726c4a05 100644 --- a/hyper/http20/util.py +++ b/hyper/http20/util.py @@ -56,5 +56,8 @@ def h2_safe_headers(headers): for i in v.split(b',') } stripped.add(b'connection') - - return [header for header in headers if header[0] not in stripped] + if hasattr(headers, 'iter_raw'): + iter_raw = headers.iter_raw() + else: + iter_raw = headers + return [header for header in iter_raw if header[0] not in stripped] diff --git a/test/test_hyper.py b/test/test_hyper.py index b826c63c..dc86385a 100644 --- a/test/test_hyper.py +++ b/test/test_hyper.py @@ -1355,6 +1355,12 @@ def test_stripping_multiple_connection_headers(self): assert h2_safe_headers(headers) == stripped + def test_stripping_headers_leaves_commas_and_space_intact(self): + headers = HTTPHeaderMap(**{'one': 'two, three, four'}) + stripped = [(b'one', b'two, three, four')] + + assert h2_safe_headers(headers) == stripped + def test_goaway_frame_PROTOCOL_ERROR(self): f = GoAwayFrame(0) # Set error code to PROTOCOL_ERROR