Skip to content

Commit 56d5801

Browse files
Response bodies included in debug output (#694)
1 parent 1f0928f commit 56d5801

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

linodecli/api_request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,16 @@ def _print_response_debug_info(response):
300300
"""
301301
# these come back as ints, convert to HTTP version
302302
http_version = response.raw.version / 10
303+
body = response.content.decode("utf-8", errors="replace")
303304

304305
print(
305306
f"< HTTP/{http_version:.1f} {response.status_code} {response.reason}",
306307
file=sys.stderr,
307308
)
308309
for k, v in response.headers.items():
309310
print(f"< {k}: {v}", file=sys.stderr)
311+
print("< Body:", file=sys.stderr)
312+
print("< ", body or "", file=sys.stderr)
310313
print("< ", file=sys.stderr)
311314

312315

tests/unit/test_api_request.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_response_debug_info(self):
2828
status_code=200,
2929
reason="OK",
3030
headers={"cool": "test"},
31+
content=b"cool body",
3132
)
3233

3334
with contextlib.redirect_stderr(stderr_buf):
@@ -36,6 +37,9 @@ def test_response_debug_info(self):
3637
output = stderr_buf.getvalue()
3738
assert "< HTTP/1.1 200 OK" in output
3839
assert "< cool: test" in output
40+
assert "< Body:" in output
41+
assert "< cool body" in output
42+
assert "< " in output
3943

4044
def test_request_debug_info(self):
4145
stderr_buf = io.StringIO()

0 commit comments

Comments
 (0)