Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-87497: Explicit that headers sent in camel-case #24661

Merged
merged 3 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ __pycache__
.hg/
.svn/
.idea/
.project
.settings/
axel3rd marked this conversation as resolved.
Show resolved Hide resolved
tags
TAGS
.vs/
Expand Down
1 change: 1 addition & 0 deletions Doc/library/urllib.request.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ The following classes are provided:
(X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"``, while
:mod:`urllib`'s default user agent string is
``"Python-urllib/2.6"`` (on Python 2.6).
All header keys are sent in camel case.

An appropriate ``Content-Type`` header should be included if the *data*
argument is present. If this header has not been provided and *data*
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_urllib2_localnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,15 @@ def test_sending_headers(self):
pass
self.assertEqual(handler.headers_received["Range"], "bytes=20-39")

def test_sending_headers_camel(self):
handler = self.start_server()
req = urllib.request.Request("http://localhost:%s/" % handler.port,
headers={"X-SoMe-hEader": "foobar"})
with urllib.request.urlopen(req):
pass
self.assertIn("X-Some-Header", handler.headers_received.keys())
self.assertNotIn("X-SoMe-hEader", handler.headers_received.keys())

def test_basic(self):
handler = self.start_server()
with urllib.request.urlopen("http://localhost:%s" % handler.port) as open_url:
Expand Down