Skip to content

Commit 42bc1c9

Browse files
updated tests:
- test_overwrite_non_singular_header - singular header must not change. - other - added more checks.
1 parent bf20b84 commit 42bc1c9

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

t_modify_http_headers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__all__ = ["test_common_config", "test_common_config_h2"]
1+
__all__ = ["test_common_config", "test_common_config_h2", "test_logic"]
22

33
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

t_modify_http_headers/test_logic.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,34 @@ def test_overwrite_singular_header(self):
8383
self.assertNotIn("tempesta", list(server.last_request.headers.find_all("host")))
8484

8585
def test_overwrite_non_singular_header(self):
86-
"""New value for header must be added to old value as list."""
86+
"""New value for header must not be added."""
8787
self.directive = f"{self.directive}_hdr_add"
8888
client, server = self.base_scenario(
8989
config=f'{self.directive} Content-Encoding "br";\n',
90-
expected_headers=[("content-encoding", "gzip, br")],
90+
expected_headers=[("content-encoding", "gzip")],
9191
)
9292
if self.directive == "req_hdr_add":
93-
self.assertNotIn("gzip", list(server.last_request.headers.find_all("content-encoding")))
93+
self.assertNotIn("br", list(server.last_request.headers.find_all("content-encoding")))
9494
else:
95-
self.assertNotIn("gzip", list(client.last_response.headers.items("content-encoding")))
95+
self.assertNotIn("br", list(client.last_response.headers.find_all("content-encoding")))
9696

9797
def test_add_exist_header(self):
9898
"""Header will be modified if 'header-value' is in base request/response."""
9999
self.directive = f"{self.directive}_hdr_add"
100-
self.base_scenario(
100+
client, server = self.base_scenario(
101101
config=f'{self.directive} x-my-hdr "original text";\n',
102102
expected_headers=[("x-my-hdr", "original text, original text")],
103103
)
104+
if self.directive == "req_hdr_add":
105+
self.assertNotIn(
106+
"original text", list(server.last_request.headers.find_all("x-my-hdr"))
107+
)
108+
else:
109+
self.assertNotIn(
110+
"original text", list(client.last_response.headers.find_all("x-my-hdr"))
111+
)
104112

105-
def test_add_large_header(self):
113+
def test_set_large_header(self):
106114
self.directive = f"{self.directive}_hdr_set"
107115
self.base_scenario(
108116
config=f'{self.directive} x-my-hdr "{"12345" * 2000}";\n',
@@ -176,6 +184,7 @@ def test_overwrite_singular_header(self):
176184
)
177185

178186
self.assertNotIn('"asd"', list(client.last_response.headers.find_all("Etag")))
187+
self.assertNotIn("asd", list(client.last_response.headers.find_all("Etag")))
179188
self.assertNotIn('"qwe", "asd"', list(client.last_response.headers.find_all("Etag")))
180189

181190

@@ -189,6 +198,7 @@ class TestReqHeaderH2(H2Config, TestReqHeader):
189198
(":path", "/"),
190199
(":scheme", "https"),
191200
(":method", "GET"),
201+
("host", "localhost"),
192202
("x-my-hdr", "original text"),
193203
("x-my-hdr", "original text"),
194204
("content-encoding", "gzip"),
@@ -222,5 +232,5 @@ def test_add_header_from_dynamic_table(self):
222232
self.assertIn(b"\xbe", client.response_buffer)
223233

224234

225-
class TestCachedRespHeaderH2(H2Config, TestCachedRespHeader):
226-
pass
235+
class TestCachedRespHeaderH2(TestRespHeaderH2):
236+
cache = True

0 commit comments

Comments
 (0)