[Django] #35440: Update parse_header_parameters to leverage the parsing logic from (stdlib) email Message.

55 views
Skip to first unread message

Django

unread,
May 8, 2024, 1:11:24 PM5/8/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
------------------------------------------------+------------------------
Reporter: Natalia Bidart | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Following a security report, which was concluded not to be such, the
Security Team agreed to apply a few improvements to the
`parse_header_parameters` function from `django/utils/http.py`.

This function was historically using Python's (now deprecated) `cgi`
module, but in 34e2148fc725e7200050f74130d7523e3cd8507a the code was
changed by porting the `cgi` implementations into the file to avoid the
deprecation (this was in the context of #33173). Later on the header
parsing logic was cleaned up in d4d5427571b4bf3a21c902276c2a00215c2a37cc
to unify the logic with the one used in the `multipartparser.py` module
(see #33697).

At the time of the `cgi` deprecation, the
[https://peps.python.org/pep-0594/#cgi PEP including the deprecation]
mentions:

> Replacements for the various parts of cgi which are not directly related
to executing code are: [ ... ] parse_header with email.message.Message
(see example below)

Providing an explicit example of how close `parse_header` and
`email.message.Message` are:

{{{#!python
>>> from cgi import parse_header
>>> from email.message import Message
>>> parse_header(h)
('application/json', {'charset': 'utf8'})
>>> m = Message()
>>> m['content-type'] = h
>>> m.get_params()
[('application/json', ''), ('charset', 'utf8')]
>>> m.get_param('charset')
}}}

The goal of this ticket is to track the improvement of the current
`parse_header_parameters` implementation by leveraging the logic from
`email.message.Message`
--
Ticket URL: <https://code.djangoproject.com/ticket/35440>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 8, 2024, 1:20:40 PM5/8/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Natalia Bidart:

Old description:
New description:
`email.message.Message`.

The Security Team also agreed that it's worth adding some early checks in
the `parse_header_parameters` function to limit the amount of provided
semicolons. This would require some investigation as to what would be a
good threshold, considering that it's likely that more than one semicolon
may not be necessary in valid HTTP headers.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:1>

Django

unread,
May 9, 2024, 2:25:03 AM5/9/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by David Smith):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:2>

Django

unread,
Jul 26, 2024, 2:41:16 PM7/26/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: chudilo
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by chudilo):

* owner: nobody => chudilo
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:3>

Django

unread,
Jul 29, 2024, 4:41:46 PM7/29/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Khudyakov Artem):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:4>

Django

unread,
Jul 29, 2024, 4:51:04 PM7/29/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Khudyakov Artem):

* has_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:5>

Django

unread,
Jul 29, 2024, 4:54:45 PM7/29/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Khudyakov Artem):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/18424 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:6>

Django

unread,
Aug 1, 2024, 10:52:07 AM8/1/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 0 => 1

Comment:

Setting as patch needs improvements following my comments in the PR (the
goal of this ticket is, ideally, to remove/replace our custom parsing
logic with Python stdlib's `Message` methods).
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:7>

Django

unread,
Aug 5, 2024, 3:45:43 AM8/5/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Khudyakov Artem):

* needs_better_patch: 1 => 0

Comment:

I've proposed a fix in the PR, but have clarifying questions. In case this
task is not on the review radar, I change the status, but am ready to make
further modifications.
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:8>

Django

unread,
Nov 22, 2024, 7:05:07 AM11/22/24
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:9>

Django

unread,
Jan 30, 2025, 1:54:43 PM1/30/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Khudyakov Artem):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:10>

Django

unread,
Feb 23, 2025, 5:23:43 AM2/23/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Shai Berger):

* cc: Shai Berger (added)
* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:11>

Django

unread,
Mar 26, 2025, 3:18:22 PM3/26/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:12>

Django

unread,
Mar 27, 2025, 7:57:14 AM3/27/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: closed
Component: HTTP handling | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by nessita <124304+nessita@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"9aabe7eae3eeb3e64c5a0f3687118cd806158550" 9aabe7e]:
{{{#!CommitTicketReference repository=""
revision="9aabe7eae3eeb3e64c5a0f3687118cd806158550"
Fixed #35440 -- Simplified parse_header_parameters by leveraging stdlid's
Message.

The `parse_header_parameters` function historically used Python's `cgi`
module (now deprecated). In 34e2148fc725e7200050f74130d7523e3cd8507a,
the logic was inlined to work around this deprecation ( #33173). Later,
in d4d5427571b4bf3a21c902276c2a00215c2a37cc, the header parsing logic
was further cleaned up to align with `multipartparser.py` (#33697).

This change takes it a step further by replacing the copied `cgi` logic
with
Python's `email.message.Message` API for a more robust and maintainable
header
parsing implementation.

Thanks to Raphael Gaschignard for testing, and to Adam Johnson and Shai
Berger for reviews.

Co-authored-by: Ben Cail <bc...@crossway.org>
Co-authored-by: Natalia <124304+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:13>

Django

unread,
Sep 15, 2025, 9:15:01 PM9/15/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: closed
Component: HTTP handling | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by nessita <124304+nessita@…>):

In [changeset:"424e0d86973d88b402b55f20884938715aad740b" 424e0d86]:
{{{#!CommitTicketReference repository=""
revision="424e0d86973d88b402b55f20884938715aad740b"
Fixed #36520 -- Reverted "Fixed #35440 -- Simplified
parse_header_parameters by leveraging stdlid's Message."

This partially reverts commit 9aabe7eae3eeb3e64c5a0f3687118cd806158550.

The simplification of parse_header_parameters using stdlib's Message
is reverted due to a performance regression. The check for the header
maximum length remains in place, per Security Team guidance.

Thanks to David Smith for reporting the regression, and Jacob Walls for
the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:14>

Django

unread,
Sep 15, 2025, 9:33:30 PM9/15/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Khudyakov
Type: | Artem
Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* has_patch: 1 => 0
* resolution: fixed =>
* stage: Ready for checkin => Accepted
* status: closed => new

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:15>

Django

unread,
Sep 15, 2025, 9:34:15 PM9/15/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: (none)
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Natalia Bidart):

* owner: Khudyakov Artem => (none)
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:16>

Django

unread,
Sep 16, 2025, 7:38:45 AM9/16/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Natalia Bidart):

* status: assigned => new

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:17>

Django

unread,
Sep 16, 2025, 8:10:29 AM9/16/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Carlton Gibson):

Just to say, I think this is the right decision here. 👏 Even if we
remerge the same thing later, having time to measure twice seems right to
me. Thanks for all the consideration that's gone into it.
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:18>

Django

unread,
Dec 29, 2025, 3:08:35 PM12/29/25
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Naveed Qadir):

I ran into this ticket while working on Accept header parsing. I agree
that moving toward a stdlib-based solution is the right long-term
direction, particularly given the previous performance concerns.
While complex quoted parameters in Accept headers appear to be very rare
in real-world traffic, incorrect handling can still lead to broken parsing
for otherwise valid headers, so it seems important that the eventual
approach handles these cases correctly.
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:19>

Django

unread,
Jan 8, 2026, 7:25:59 AMJan 8
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Pravin):

I tried using a simple string split for normal headers, and only uses
{{{email.message}}} when it sees complex symbols like " or *.


{{{
def _parse_header_params(line):
"""The 'Slower' logic."""
m = Message()
m["content-type"] = line
params = m.get_params()
if not params:
return "", {}

pdict = {}

key = params.pop(0)[0].lower()

for name, value in params:
if not name:
continue
if isinstance(value, tuple):
value = collapse_rfc2231_value(value)
pdict[name] = value
return key, pdict

def parse_header_parameters(line, max_length=MAX_HEADER_LENGTH):
"""
Parse a Content-type like header.
Return the main content-type and a dictionary of options.

If `line` is longer than `max_length`, `ValueError` is raised.
"""
if not line:
return "", {}

if max_length is not None and len(line) > max_length:
raise ValueError("Unable to parse header parameters (value too
long).")

if ";" not in line:
return line.lower().strip(), {}

if '"' not in line and "*" not in line:
parts = line.split(";")
key = parts[0].lower().strip()
pdict = {}
for p in parts[1:]:
if "=" in p:
name, value = p.split("=", 1)
pdict[name.lower().strip()] = value.strip()
return key, pdict

return _parse_header_params(line)
}}}


I ran a benchmark with 50,000 iterations. Here are my results:

{{{
Test Case Existing New implementation
Simple (no params) 0.050s 0.016s
Standard (charset) 0.109s 0.044s
Complex (quotes) 0.214s 0.681s
}}}

for me this make sense , It will rarely happened that there would be a
complex case for parsing.
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:20>

Django

unread,
Jan 11, 2026, 11:31:07 PMJan 11
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: Pravin
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Pravin):

* owner: (none) => Pravin
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:21>

Django

unread,
Jan 13, 2026, 8:25:56 AM (13 days ago) Jan 13
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: Pravin
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Pravin):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:22>

Django

unread,
Jan 13, 2026, 8:42:56 AM (13 days ago) Jan 13
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: Pravin
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:23>

Django

unread,
Jan 13, 2026, 9:33:07 AM (13 days ago) Jan 13
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: Pravin
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Pravin):

* Attachment "diff.txt" added.

Django

unread,
Jan 13, 2026, 9:34:59 AM (13 days ago) Jan 13
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: Pravin
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Pravin):

* Attachment "bench_mark.py" added.

This small adjustment i made.

Django

unread,
Jan 13, 2026, 9:44:29 AM (13 days ago) Jan 13
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: Pravin
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Pravin):

my previous suggestion was failing for one test case.

So I wrote new simple patch as below modifying the existing one as below
in the diff
attachment:diff.txt

and i ran 9 to 10 times attachment:bench_mark.py
50,000 iterations for each. and following result i got on average. I used
linux i3 8gb 5 year old laptop may be that's why i'm getting fluctuations
in the results.

Complex test case (which triggers the fallback), results varied between
-73% and +42% across runs.

{{{
Test Case Original Avg Time Optimized Avg
Time Improvement (Avg)
Simple (No Params) ~0.047s ~0.012s
~73%
Standard (Charset) ~0.110s ~0.045s
~59%
Multi-Param ~0.190s ~0.065s
~65%
Complex (RFC 2231) ~0.650s ~0.530s
Variable*
}}}

Below are the sampled results when i ran attachment:bench_mark.py for 15
consecutive times:


{{{
Run | Simple | Standard | Multi-P | Complex |
----------------------------------------------
1 | 70.26% | 63.36% | 65.50% | -2.99% |
2 | 66.09% | 57.83% | 63.27% | -34.87% |
3 | 73.31% | 57.90% | 59.09% | -17.48% |
4 | 78.64% | 58.98% | 65.31% | 36.69% |
5 | 74.02% | 59.89% | 60.66% | 39.80% |
6 | 74.90% | 58.15% | 53.38% | 23.74% |
7 | 74.85% | 60.53% | 65.36% | 33.77% |
8 | 71.63% | 53.78% | 54.52% | 28.88% |
9 | 72.75% | 53.04% | 65.91% | 33.18% |
10 | 71.69% | 60.46% | 64.59% | -14.10% |
11 | 75.16% | 61.84% | 67.22% | 36.87% |
12 | 74.15% | 58.61% | 64.92% | -73.24% |
13 | 72.17% | 56.63% | 63.03% | 33.01% |
14 | 73.14% | 47.98% | 64.39% | 24.96% |
15 | 73.54% | 57.26% | 64.47% | 25.37% |
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:24>

Django

unread,
Jan 13, 2026, 10:16:26 AM (13 days ago) Jan 13
to django-...@googlegroups.com
#35440: Update parse_header_parameters to leverage the parsing logic from (stdlib)
email Message.
--------------------------------------+------------------------------------
Reporter: Natalia Bidart | Owner: Pravin
Type: Cleanup/optimization | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Pravin):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:25>
Reply all
Reply to author
Forward
0 new messages