]> granicus.if.org Git - python/commitdiff
bpo-33365: print the header values beside the keys (GH-6611)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 19 Jun 2018 13:52:36 +0000 (06:52 -0700)
committerGitHub <noreply@github.com>
Tue, 19 Jun 2018 13:52:36 +0000 (06:52 -0700)
with debuglevel=1 only the header keys got printed. With
this change the header values get printed as well and the single
header entries get '\n' as a separator.
(cherry picked from commit 936f03e7fafc28fd6fdfba11d162c776b89c0167)

Co-authored-by: Marco Strigl <mstrigl@suse.com>
Lib/http/client.py
Lib/test/test_httplib.py
Misc/NEWS.d/next/Library/2018-05-08-15-01-10.bpo-33365.SicsAd.rst [new file with mode: 0644]

index 1292db74784cccdc4bf186d51b394e11d20e67a1..5aa178d7b127d90de276dbd627c48304f39eacbf 100644 (file)
@@ -321,7 +321,7 @@ class HTTPResponse(io.BufferedIOBase):
 
         if self.debuglevel > 0:
             for hdr in self.headers:
-                print("header:", hdr, end=" ")
+                print("header:", hdr + ":", self.headers.get(hdr))
 
         # are we using the chunked-style of transfer encoding?
         tr_enc = self.headers.get("transfer-encoding")
index a3f8194dc44fcf157c6c00f4ab29163591b1772c..f816eac83b682dfa725c389db967446c597c0b0f 100644 (file)
@@ -344,6 +344,21 @@ class HeaderTests(TestCase):
                 with self.assertRaisesRegex(ValueError, 'Invalid header'):
                     conn.putheader(name, value)
 
+    def test_headers_debuglevel(self):
+        body = (
+            b'HTTP/1.1 200 OK\r\n'
+            b'First: val\r\n'
+            b'Second: val\r\n'
+        )
+        sock = FakeSocket(body)
+        resp = client.HTTPResponse(sock, debuglevel=1)
+        with support.captured_stdout() as output:
+            resp.begin()
+        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")
+
 
 class TransferEncodingTest(TestCase):
     expected_body = b"It's just a flesh wound"
diff --git a/Misc/NEWS.d/next/Library/2018-05-08-15-01-10.bpo-33365.SicsAd.rst b/Misc/NEWS.d/next/Library/2018-05-08-15-01-10.bpo-33365.SicsAd.rst
new file mode 100644 (file)
index 0000000..41c273f
--- /dev/null
@@ -0,0 +1 @@
+Print the header values besides the header keys instead just the header keys if *debuglevel* is set to >0 in :mod:`http.client`. Patch by Marco Strigl.