summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-06-19 13:52:44 (GMT)
committerGitHub <noreply@github.com>2018-06-19 13:52:44 (GMT)
commit34cd4821ed97639896f85bdf0c0d5c75b23f8a76 (patch)
tree769cf8fa4c7dc3bafbb2318ded4c6067ee22c6b5
parent8c19a44b63033e9c70e9b552476baecb6e3e9451 (diff)
downloadcpython-34cd4821ed97639896f85bdf0c0d5c75b23f8a76.zip
cpython-34cd4821ed97639896f85bdf0c0d5c75b23f8a76.tar.gz
cpython-34cd4821ed97639896f85bdf0c0d5c75b23f8a76.tar.bz2
bpo-33365: print the header values beside the keys (GH-6611)
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>
-rw-r--r--Lib/http/client.py2
-rw-r--r--Lib/test/test_httplib.py15
-rw-r--r--Misc/NEWS.d/next/Library/2018-05-08-15-01-10.bpo-33365.SicsAd.rst1
3 files changed, 17 insertions, 1 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 8a82c57..baabfeb 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -322,7 +322,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")
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 64d6e43..714d521 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -343,6 +343,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
index 0000000..41c273f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-05-08-15-01-10.bpo-33365.SicsAd.rst
@@ -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.