|
9 | 9 |
|
10 | 10 | import hyperframe |
11 | 11 | import pytest |
| 12 | +from hpack import HeaderTuple |
12 | 13 |
|
13 | 14 | import h2.config |
14 | 15 | import h2.connection |
@@ -789,6 +790,48 @@ def test_headers_are_lowercase(self, frame_factory): |
789 | 790 |
|
790 | 791 | assert c.data_to_send() == expected_frame.serialize() |
791 | 792 |
|
| 793 | + def test_outbound_cookie_headers_are_split(self): |
| 794 | + """ |
| 795 | + We should split outbound cookie headers according to |
| 796 | + RFC 7540 - 8.1.2.5 |
| 797 | + """ |
| 798 | + cookie_headers = [ |
| 799 | + HeaderTuple('cookie', |
| 800 | + 'username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC'), |
| 801 | + ('cookie', 'path=1'), |
| 802 | + ('cookie', 'test1=val1; test2=val2') |
| 803 | + ] |
| 804 | + |
| 805 | + expected_cookie_headers = [ |
| 806 | + HeaderTuple('cookie', 'username=John Doe'), |
| 807 | + HeaderTuple('cookie', 'expires=Thu, 18 Dec 2013 12:00:00 UTC'), |
| 808 | + ('cookie', 'path=1'), |
| 809 | + ('cookie', 'test1=val1'), |
| 810 | + ('cookie', 'test2=val2'), |
| 811 | + ] |
| 812 | + |
| 813 | + client_config = h2.config.H2Configuration( |
| 814 | + client_side=True, |
| 815 | + header_encoding='utf-8', |
| 816 | + split_outbound_cookies=True |
| 817 | + ) |
| 818 | + server_config = h2.config.H2Configuration( |
| 819 | + client_side=False, |
| 820 | + normalize_inbound_headers=False, |
| 821 | + header_encoding='utf-8' |
| 822 | + ) |
| 823 | + client = h2.connection.H2Connection(config=client_config) |
| 824 | + server = h2.connection.H2Connection(config=server_config) |
| 825 | + |
| 826 | + client.initiate_connection() |
| 827 | + client.send_headers(1, self.example_request_headers + cookie_headers, end_stream=True) |
| 828 | + |
| 829 | + e = server.receive_data(client.data_to_send()) |
| 830 | + |
| 831 | + cookie_fields = [(n, v) for n, v in e[1].headers if n == 'cookie'] |
| 832 | + |
| 833 | + assert cookie_fields == expected_cookie_headers |
| 834 | + |
792 | 835 | @given(frame_size=integers(min_value=2**14, max_value=(2**24 - 1))) |
793 | 836 | @settings(suppress_health_check=[HealthCheck.function_scoped_fixture]) |
794 | 837 | def test_changing_max_frame_size(self, frame_factory, frame_size): |
|
0 commit comments