summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-04-14 02:45:56 (GMT)
committerGitHub <noreply@github.com>2022-04-14 02:45:56 (GMT)
commit0ab5e83ff78e5e871768440ab0a7030bc825398f (patch)
treebebd046972a88ac570342736dd98eea4d8ed70bc
parentedf1a77f239069235f59103cfd8ce7f939c7fd10 (diff)
downloadcpython-0ab5e83ff78e5e871768440ab0a7030bc825398f.zip
cpython-0ab5e83ff78e5e871768440ab0a7030bc825398f.tar.gz
cpython-0ab5e83ff78e5e871768440ab0a7030bc825398f.tar.bz2
gh-87497: Document that urllib.request sends headers in camel case (GH-24661)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 325d6f50357474c7d9fd2475be0e2481f7ae0476) Co-authored-by: Alix Lourme <alix.lourme@gmail.com>
-rw-r--r--Doc/library/urllib.request.rst1
-rw-r--r--Lib/test/test_urllib2_localnet.py9
2 files changed, 10 insertions, 0 deletions
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
index bfb994e..1307143 100644
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -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*
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index 74374c0..162e356 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -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: