[Python-checkins] bpo-36522: Print all values for headers with multiple values. (GH-12681)
Serhiy Storchaka
webhook-mailer at python.org
Thu Apr 4 00:36:53 EDT 2019
https://github.com/python/cpython/commit/461c416dd78a98f2bba7f323af8c9738e060b6f2
commit: 461c416dd78a98f2bba7f323af8c9738e060b6f2
branch: master
author: Matt Houglum <houglum at google.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2019-04-04T07:36:47+03:00
summary:
bpo-36522: Print all values for headers with multiple values. (GH-12681)
files:
A Misc/NEWS.d/next/Library/2019-04-03-20-46-47.bpo-36522.g5x3By.rst
M Lib/http/client.py
M Lib/test/test_httplib.py
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 5aa178d7b127..1de151c38e92 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -320,8 +320,8 @@ def begin(self):
self.headers = self.msg = parse_headers(self.fp)
if self.debuglevel > 0:
- for hdr in self.headers:
- print("header:", hdr + ":", self.headers.get(hdr))
+ for hdr, val in self.headers.items():
+ print("header:", hdr + ":", val)
# are we using the chunked-style of transfer encoding?
tr_enc = self.headers.get("transfer-encoding")
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index f816eac83b68..4755f8b4b9de 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -348,7 +348,8 @@ def test_headers_debuglevel(self):
body = (
b'HTTP/1.1 200 OK\r\n'
b'First: val\r\n'
- b'Second: val\r\n'
+ b'Second: val1\r\n'
+ b'Second: val2\r\n'
)
sock = FakeSocket(body)
resp = client.HTTPResponse(sock, debuglevel=1)
@@ -357,7 +358,8 @@ def test_headers_debuglevel(self):
lines = output.getvalue().splitlines()
self.assertEqual(lines[0], "reply: 'HTTP/1.1 200 OK\\r\\n'")
self.assertEqual(lines[1], "header: First: val")
- self.assertEqual(lines[2], "header: Second: val")
+ self.assertEqual(lines[2], "header: Second: val1")
+ self.assertEqual(lines[3], "header: Second: val2")
class TransferEncodingTest(TestCase):
diff --git a/Misc/NEWS.d/next/Library/2019-04-03-20-46-47.bpo-36522.g5x3By.rst b/Misc/NEWS.d/next/Library/2019-04-03-20-46-47.bpo-36522.g5x3By.rst
new file mode 100644
index 000000000000..7869526b71c7
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-04-03-20-46-47.bpo-36522.g5x3By.rst
@@ -0,0 +1 @@
+If *debuglevel* is set to >0 in :mod:`http.client`, print all values for headers with multiple values for the same header name. Patch by Matt Houglum.
More information about the Python-checkins
mailing list