From 09f27cc373eb1e6e5e8b286204809a79b61d55c3 Mon Sep 17 00:00:00 2001 From: Pravin Kamble Date: Tue, 13 Jan 2026 20:21:50 +0530 Subject: Refs #35440 -- Optimized parse_header_parameters() for the simplest case. Added a fast-path to parse_header_parameters Benchmark results (50,000 iterations): - Simple headers: ~73% improvement Thanks Nick Pope (@ngnpope) for the review. --- django/utils/http.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/django/utils/http.py b/django/utils/http.py index 2950f3e695..f72f54e958 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -342,6 +342,10 @@ def parse_header_parameters(line, max_length=MAX_HEADER_LENGTH): if max_length is not None and len(line) > max_length: raise ValueError("Unable to parse header parameters (value too long).") + # Fast path for no params. + if ";" not in line: + return line.strip().lower(), {} + parts = _parseparam(";" + line) key = parts.__next__().lower() pdict = {} -- cgit v1.3