[Python-checkins] gh-87497: Document that urllib.request sends headers in camel case (GH-24661)
JelleZijlstra
webhook-mailer at python.org
Wed Apr 13 22:19:26 EDT 2022
https://github.com/python/cpython/commit/325d6f50357474c7d9fd2475be0e2481f7ae0476
commit: 325d6f50357474c7d9fd2475be0e2481f7ae0476
branch: main
author: Alix Lourme <alix.lourme at gmail.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-04-13T19:19:16-07:00
summary:
gh-87497: Document that urllib.request sends headers in camel case (GH-24661)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra at gmail.com>
files:
M Doc/library/urllib.request.rst
M Lib/test/test_urllib2_localnet.py
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
index 88e93ba6b002e..a8501ab863968 100644
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -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*
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index 36314312ac0eb..f4729358557c9 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -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:
More information about the Python-checkins
mailing list