]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.15] gh-47005: fix do_open() to let regular headers override unredirected … (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 9 Jul 2026 04:15:30 +0000 (06:15 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 04:15:30 +0000 (04:15 +0000)
commit9fb25cbd41410fb9bdf230d6242f0358885405ae
tree817d6a3dabfb67b0e5c155b2f6d1a35eb7164ae1
parentc512e8f0fb6b78da7fe91aa267700ea516dfd1f6
[3.15] gh-47005: fix do_open() to let regular headers override unredirected … (GH-146506) (#153377)

gh-47005: fix do_open() to let regular headers override unredirected … (GH-146506)

AbstractHTTPHandler.do_open() was building the request header dict by
starting with unredirected_hdrs and only inserting regular headers that
were not already present, giving unredirected headers priority.  This
contradicts get_header() and header_items(), both of which give regular
headers the higher priority.

Fix by unconditionally updating with req.headers so that a header set
via add_header() always overrides one set via add_unredirected_header().

---------
(cherry picked from commit 6d386684ad69f42cb57c72fe0e0ffcec82ec7e12)

Co-authored-by: CHINMAY <89741289+Das-Chinmay@users.noreply.github.com>
Co-authored-by: Senthil Kumaran <senthil@python.org>
Lib/test/test_urllib2.py
Lib/urllib/request.py
Misc/NEWS.d/next/Library/2026-03-26-00-00-00.gh-issue-47005.xxc89c.rst [new file with mode: 0644]