Skip to content

feat: allow custom headers in urlopener + pass to it from urlopen#770

Open
seemab-yamin wants to merge 2 commits intoAnswerDotAI:mainfrom
seemab-yamin:fix-net-urlopener-add-missing-header-param
Open

feat: allow custom headers in urlopener + pass to it from urlopen#770
seemab-yamin wants to merge 2 commits intoAnswerDotAI:mainfrom
seemab-yamin:fix-net-urlopener-add-missing-header-param

Conversation

@seemab-yamin
Copy link
Contributor

@seemab-yamin seemab-yamin commented Feb 3, 2026

What this does
Allows passing custom headers directly to urlopener(headers=...) (previously it always used only url_default_headers).
Also propagates user headers from urlopen/urlread/etc → urlopener, so custom headers can override or add to defaults.

Why
Before, even if you passed headers= to urlopen, they only went to the Request object — the opener-level defaults were never combined or overridable per-call.

Repro before fix (fails to send custom headers at opener level)

from fastcore.net import urlread

url = "https://httpbin.org/headers"
headers = {"X-Custom-Header": "should-appear"}

resp = urlread(url, headers=headers)
print(resp)  # X-Custom-Header missing from response (only defaults applied)

@seemab-yamin seemab-yamin changed the title fix url* functions: propagate headers param to underlying Request feat: allow custom headers in urlopener + pass to it from urlopen Feb 3, 2026
@seemab-yamin
Copy link
Contributor Author

@jph00 - Please review and let me know if there is any fix or style improvement. Thanks for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant