]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-87497: Document that urllib.request sends headers in camel case (GH-24661)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 14 Apr 2022 02:45:56 +0000 (19:45 -0700)
committerGitHub <noreply@github.com>
Thu, 14 Apr 2022 02:45:56 +0000 (19:45 -0700)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 325d6f50357474c7d9fd2475be0e2481f7ae0476)

Co-authored-by: Alix Lourme <alix.lourme@gmail.com>
Doc/library/urllib.request.rst
Lib/test/test_urllib2_localnet.py

index bfb994e315468f29bd31335349b1ed36f62b7133..1307143a04f1d8deb37e6a2cabad44b48ddfb0a3 100644 (file)
@@ -213,6 +213,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 74374c08684da2f8bfdbb5e7d42ffae185da9f3b..162e356d1f1bb74d49e834c90238f32a9be06c72 100644 (file)
@@ -613,6 +613,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: