Fixed --max-redirects

This commit is contained in:
Jakub Roztocil 2016-02-29 14:21:25 +08:00
parent 356e043651
commit e18b609ef7
4 changed files with 9 additions and 4 deletions

View File

@ -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=<limit>`` option.
.. code-block:: bash
$ http --follow --show-redirects --max-redirects=5 httpbin.org/redirect/3
=======
Proxies
=======

View File

@ -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)

View File

@ -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)

View File

@ -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