From 87a85bb4de18ab17c360f7cb530274202fd05d4c Mon Sep 17 00:00:00 2001 From: Arnaud Schoonjans Date: Mon, 15 Dec 2025 12:12:18 +0100 Subject: [PATCH] Make sure that the in-operator on HTTPHeaders is case insensitive --- tornado/httputil.py | 3 ++- tornado/test/httputil_test.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tornado/httputil.py b/tornado/httputil.py index 13a95d90..74dfb87f 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -345,7 +345,8 @@ class HTTPHeaders(StrMutableMapping): # in __getitem__ when it's not needed. if not isinstance(name, str): return False - return name in self._as_list + norm_name = _normalize_header(name) + return norm_name in self._as_list def __getitem__(self, name: str) -> str: header = _normalize_header(name) diff --git a/tornado/test/httputil_test.py b/tornado/test/httputil_test.py index 7fa528cd..9c7ee093 100644 --- a/tornado/test/httputil_test.py +++ b/tornado/test/httputil_test.py @@ -329,6 +329,9 @@ Foo: even sorted(list(headers.get_all())), [("Asdf", "qwer zxcv"), ("Foo", "bar baz"), ("Foo", "even more lines")], ) + # Verify case insensitivity in-operator + self.assertTrue("asdf" in headers) + self.assertTrue("Asdf" in headers) def test_continuation(self): data = "Foo: bar\r\n\tasdf" -- 2.47.3