Skip to content

Commit 325d6f5

Browse files
pythongh-87497: Document that urllib.request sends headers in camel case (pythonGH-24661)
Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 5f056ac commit 325d6f5

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
@@ -617,6 +617,15 @@ def test_sending_headers(self):
617617
pass
618618
self.assertEqual(handler.headers_received["Range"], "bytes=20-39")
619619

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

0 commit comments

Comments
 (0)