From 2d55c01c7ecae1fcf84b61ac502f947dd3d7e280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Schoentgen?= Date: Tue, 15 Jun 2021 13:39:46 +0200 Subject: [PATCH] Fix printing redirected prepared request in verbose mode (#1088) --- httpie/core.py | 6 +++--- tests/test_redirects.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/httpie/core.py b/httpie/core.py index 1cb1c8b4..cf2567d4 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -177,10 +177,10 @@ def program(args: argparse.Namespace, env: Environment) -> ExitStatus: if is_request: if not initial_request: initial_request = message + if with_body: is_streamed_upload = not isinstance(message.body, (str, bytes)) - if with_body: - do_write_body = not is_streamed_upload - force_separator = is_streamed_upload and env.stdout_isatty + do_write_body = not is_streamed_upload + force_separator = is_streamed_upload and env.stdout_isatty else: final_response = message if args.check_status or downloader: diff --git a/tests/test_redirects.py b/tests/test_redirects.py index 176654c4..9f2648cf 100644 --- a/tests/test_redirects.py +++ b/tests/test_redirects.py @@ -2,6 +2,7 @@ import pytest from httpie.status import ExitStatus +from .fixtures import FILE_PATH_ARG from .utils import http, HTTP_OK @@ -57,3 +58,19 @@ def test_max_redirects(httpbin): tolerate_error_exit_status=True, ) assert r.exit_status == ExitStatus.ERROR_TOO_MANY_REDIRECTS + + +def test_http_307_allow_redirect_post(httpbin): + r = http('--follow', 'POST', httpbin.url + '/redirect-to', + f'url=={httpbin.url}/post', 'status_code==307', + '@' + FILE_PATH_ARG) + assert HTTP_OK in r + + +def test_http_307_allow_redirect_post_verbose(httpbin): + r = http('--follow', '--verbose', 'POST', httpbin.url + '/redirect-to', + f'url=={httpbin.url}/post', 'status_code==307', + '@' + FILE_PATH_ARG) + assert r.count('POST /redirect-to') == 1 + assert r.count('POST /post') == 1 + assert HTTP_OK in r