File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ def normalize_headers(
3030 or "\r " in value
3131 ):
3232 raise HyperbrowserError ("headers must not contain newline characters" )
33+ if normalized_key in normalized_headers :
34+ raise HyperbrowserError (
35+ "duplicate header names are not allowed after normalization"
36+ )
3337 normalized_headers [normalized_key ] = value
3438 return normalized_headers
3539
Original file line number Diff line number Diff line change @@ -200,6 +200,17 @@ def test_client_config_normalizes_header_name_whitespace():
200200 assert config .headers == {"X-Correlation-Id" : "value" }
201201
202202
203+ def test_client_config_rejects_duplicate_header_names_after_normalization ():
204+ with pytest .raises (
205+ HyperbrowserError ,
206+ match = "duplicate header names are not allowed after normalization" ,
207+ ):
208+ ClientConfig (
209+ api_key = "test-key" ,
210+ headers = {"X-Correlation-Id" : "one" , " X-Correlation-Id " : "two" },
211+ )
212+
213+
203214def test_client_config_accepts_mapping_header_inputs ():
204215 headers = MappingProxyType ({"X-Correlation-Id" : "abc123" })
205216 config = ClientConfig (api_key = "test-key" , headers = headers )
Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ def test_normalize_headers_rejects_empty_header_name():
2121 )
2222
2323
24+ def test_normalize_headers_rejects_duplicate_names_after_normalization ():
25+ with pytest .raises (
26+ HyperbrowserError ,
27+ match = "duplicate header names are not allowed after normalization" ,
28+ ):
29+ normalize_headers (
30+ {"X-Trace-Id" : "one" , " X-Trace-Id " : "two" },
31+ mapping_error_message = "headers must be a mapping of string pairs" ,
32+ )
33+
34+
2435def test_parse_headers_env_json_ignores_blank_values ():
2536 assert parse_headers_env_json (" " ) is None
2637
You can’t perform that action at this time.
0 commit comments