mirror of
https://github.com/httpie/cli.git
synced 2026-06-20 11:32:56 +02:00
Added --show-redirects and --max-redirects
Closes #157, #183, #188, #246
This commit is contained in:
1 parent
c6d4f6cdf6
commit
356e043651
7 files changed
+76
-18
No files matched your search
@@ -12,6 +12,7 @@ class ExitStatus:
|
||||
OK = 0
|
||||
ERROR = 1
|
||||
ERROR_TIMEOUT = 2
|
||||
ERROR_TOO_MANY_REDIRECTS = 6
|
||||
|
||||
# Used only when requested with --check-status:
|
||||
ERROR_HTTP_3XX = 3
|
||||
|
||||
+23
-13
@@ -380,16 +380,6 @@ sessions.add_argument(
|
||||
"""
|
||||
)
|
||||
|
||||
sessions.add_argument(
|
||||
'--max-redirects',
|
||||
dest='redirects',
|
||||
default=30,
|
||||
help="""
|
||||
By default, requests has a limit of 30 redirects.
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
#######################################################################
|
||||
# Authentication
|
||||
#######################################################################
|
||||
@@ -456,15 +446,35 @@ network.add_argument(
|
||||
"""
|
||||
)
|
||||
network.add_argument(
|
||||
'--follow',
|
||||
'--follow', '-F',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help="""
|
||||
Set this flag if full redirects are allowed (e.g. re-POST-ing of data at
|
||||
new Location).
|
||||
Follow 30x Location redirects.
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
network.add_argument(
|
||||
'--show-redirects', '-R',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help="""
|
||||
Show all responses within the redirect chain (works with --follow).
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
network.add_argument(
|
||||
'--max-redirects',
|
||||
type=int,
|
||||
default=30,
|
||||
help="""
|
||||
By default, requests have a limit of 30 redirects (works with --follow).
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
network.add_argument(
|
||||
'--verify',
|
||||
default='yes',
|
||||
|
||||
+9
-3
@@ -113,8 +113,12 @@ def main(args=sys.argv[1:], env=Environment(), error=None):
|
||||
|
||||
last_response = get_response(args, config_dir=env.config.directory)
|
||||
|
||||
redirect_chain = last_response.history + [last_response]
|
||||
for response in redirect_chain:
|
||||
if args.show_redirects:
|
||||
responses = last_response.history + [last_response]
|
||||
else:
|
||||
responses = [last_response]
|
||||
|
||||
for response in responses:
|
||||
|
||||
if exit_status != ExitStatus.OK:
|
||||
break
|
||||
@@ -183,7 +187,9 @@ def main(args=sys.argv[1:], env=Environment(), error=None):
|
||||
except requests.Timeout:
|
||||
exit_status = ExitStatus.ERROR_TIMEOUT
|
||||
error('Request timed out (%ss).', args.timeout)
|
||||
|
||||
except requests.TooManyRedirects:
|
||||
exit_status = ExitStatus.ERROR_TOO_MANY_REDIRECTS
|
||||
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.
|
||||
|
||||
Reference in new issue
Block a user