From e18b609ef7d867d6efa0efe42c832be5e0d09338 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Mon, 29 Feb 2016 14:21:25 +0800 Subject: [PATCH] Fixed --max-redirects --- README.rst | 9 +++++++-- httpie/client.py | 1 + httpie/core.py | 1 - tests/test_redirects.py | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 5b201aae..13803083 100644 --- a/README.rst +++ b/README.rst @@ -631,13 +631,18 @@ By default, HTTP redirects are not followed and only the first response is shown. To instruct HTTPie to follow the ``Location`` header of ``30x`` responses and show the final response instead, use the ``--follow, -F`` option. -If you additionally wish to see the intermediary requests/responses as well, -use the ``--show-redirects, -R`` option as well. +If you additionally wish to see the intermediary requests/responses, +then use the ``--show-redirects, -R`` option as well. To change the default limit of maximum 30 redirects, use the ``--max-redirects=`` option. +.. code-block:: bash + + $ http --follow --show-redirects --max-redirects=5 httpbin.org/redirect/3 + + ======= Proxies ======= diff --git a/httpie/client.py b/httpie/client.py index 1115f4dd..482f9dce 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -40,6 +40,7 @@ def get_response(args, config_dir): """Send the request and return a `request.Response`.""" requests_session = get_requests_session() + requests_session.max_redirects = args.max_redirects if not args.session and not args.session_read_only: kwargs = get_requests_kwargs(args) diff --git a/httpie/core.py b/httpie/core.py index c0014cea..3dbe7f2b 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -192,7 +192,6 @@ def main(args=sys.argv[1:], env=Environment(), error=None): error('Too many redirects (--max-redirects=%s).', args.max_redirects) except Exception as e: # TODO: Better distinction between expected and unexpected errors. - # Network errors vs. bugs, etc. if traceback: raise msg = str(e) diff --git a/tests/test_redirects.py b/tests/test_redirects.py index 35cf9b03..94b1fc07 100644 --- a/tests/test_redirects.py +++ b/tests/test_redirects.py @@ -17,6 +17,6 @@ class TestRedirects: assert HTTP_OK in r def test_max_redirects(self, httpbin): - r = http('--max-redirects=2', '--follow', httpbin.url + '/redirect/3', + r = http('--max-redirects=1', '--follow', httpbin.url + '/redirect/3', error_exit_ok=True) assert r.exit_status == ExitStatus.ERROR_TOO_MANY_REDIRECTS