Skip to content

Commit e08d323

Browse files
gh-87497: Document that urllib.request sends headers in camel case (GH-24661) (#91517)
Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 325d6f5) Co-authored-by: Alix Lourme <[email protected]>
1 parent 68caef8 commit e08d323

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Doc/library/urllib.request.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ The following classes are provided:
218218
(X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"``, while
219219
:mod:`urllib`'s default user agent string is
220220
``"Python-urllib/2.6"`` (on Python 2.6).
221+
All header keys are sent in camel case.
221222

222223
An appropriate ``Content-Type`` header should be included if the *data*
223224
argument is present. If this header has not been provided and *data*

Lib/test/test_urllib2_localnet.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,15 @@ def test_sending_headers(self):
614614
pass
615615
self.assertEqual(handler.headers_received["Range"], "bytes=20-39")
616616

617+
def test_sending_headers_camel(self):
618+
handler = self.start_server()
619+
req = urllib.request.Request("http://localhost:%s/" % handler.port,
620+
headers={"X-SoMe-hEader": "foobar"})
621+
with urllib.request.urlopen(req):
622+
pass
623+
self.assertIn("X-Some-Header", handler.headers_received.keys())
624+
self.assertNotIn("X-SoMe-hEader", handler.headers_received.keys())
625+
617626
def test_basic(self):
618627
handler = self.start_server()
619628
with urllib.request.urlopen("http://localhost:%s" % handler.port) as open_url:

0 commit comments

Comments
 (0)