]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-87497: Document that urllib.request sends headers in camel case (GH-24661)
authorAlix Lourme <alix.lourme@gmail.com>
Thu, 14 Apr 2022 02:19:16 +0000 (04:19 +0200)
committerGitHub <noreply@github.com>
Thu, 14 Apr 2022 02:19:16 +0000 (19:19 -0700)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Doc/library/urllib.request.rst
Lib/test/test_urllib2_localnet.py

index 88e93ba6b002eb26532a3bb432c7446decdb11ac..a8501ab863968fcaf5aa0ccd40b4c3381f2e52f7 100644 (file)
@@ -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*
index 36314312ac0eba6ef70254e404b0f817b004d16f..f4729358557c952eb2f42262b33c777894232c83 100644 (file)
@@ -617,6 +617,15 @@ class TestUrlopen(unittest.TestCase):
             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: