]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-47005: fix do_open() to let regular headers override unredirected … (#146506)
authorCHINMAY <89741289+Das-Chinmay@users.noreply.github.com>
Thu, 9 Jul 2026 03:40:18 +0000 (20:40 -0700)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 03:40:18 +0000 (20:40 -0700)
commit6d386684ad69f42cb57c72fe0e0ffcec82ec7e12
tree10a2ab415678afc25633df22414ebd54688bcb36
parentb2d8db1ac818e74ffe666146335e9e6c7f1f3f56
gh-47005: fix do_open() to let regular headers override unredirected … (#146506)

* gh-47005: fix do_open() to let regular headers override unredirected headers

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().

---------

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]