]> granicus.if.org Git - python/commitdiff
bpo-36522: Print all values for headers with multiple values. (GH-12681)
authorMatt Houglum <houglum@google.com>
Thu, 4 Apr 2019 04:36:47 +0000 (21:36 -0700)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 4 Apr 2019 04:36:47 +0000 (07:36 +0300)
Lib/http/client.py
Lib/test/test_httplib.py
Misc/NEWS.d/next/Library/2019-04-03-20-46-47.bpo-36522.g5x3By.rst [new file with mode: 0644]

index 5aa178d7b127d90de276dbd627c48304f39eacbf..1de151c38e92f1bdda963bf098d4cd37c1a8ea7a 100644 (file)
@@ -320,8 +320,8 @@ class HTTPResponse(io.BufferedIOBase):
         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")
index f816eac83b682dfa725c389db967446c597c0b0f..4755f8b4b9de0be474baf829055e631a91dd94a4 100644 (file)
@@ -348,7 +348,8 @@ class HeaderTests(TestCase):
         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 @@ class HeaderTests(TestCase):
         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 (file)
index 0000000..7869526
--- /dev/null
@@ -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.