]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] 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:33:56 +0000 (06:33 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 04:33:56 +0000 (04:33 +0000)
commitc323ea71f9d529db8c56fe5421e9bc7392cc66e5
treeb7eeca44d410f2f327b64a7568913ca9b086c4d0
parent0f529b1ca2b907ba6917dfdd298b3ff6cd8bd21a
[3.14] gh-47005: fix do_open() to let regular headers override unredirected … (GH-146506) (#153378)

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]