mirror of
https://github.com/httpie/cli.git
synced 2024-12-28 01:09:05 +01:00
Renamed --allow-redirects to --follow.
This commit is contained in:
parent
9338aadd75
commit
da0eb7db79
@ -858,7 +858,7 @@ Scripting
|
||||
When using HTTPie from **shell scripts**, it can be handy to set the
|
||||
``--check-status`` flag. It instructs HTTPie to exit with an error if the
|
||||
HTTP status is one of ``3xx``, ``4xx``, or ``5xx``. The exit status will
|
||||
be ``3`` (unless ``--allow-redirects`` is set), ``4``, or ``5``,
|
||||
be ``3`` (unless ``--follow`` is set), ``4``, or ``5``,
|
||||
respectively. Also, the ``--timeout`` option allows to overwrite the default
|
||||
30s timeout:
|
||||
|
||||
@ -993,6 +993,7 @@ Changelog
|
||||
|
||||
* `0.2.8-alpha`_
|
||||
* Added persistent session support.
|
||||
* Renamed ``--allow-redirects`` to ``--follow``.
|
||||
* Improved the usability of ``http --help``.
|
||||
* Fixed installation on Windows with Python 3.
|
||||
* Fixed colorized output on Windows with Python 3.
|
||||
|
@ -3,7 +3,7 @@
|
||||
NOTE: the CLI interface may change before reaching v1.0.
|
||||
|
||||
"""
|
||||
from argparse import FileType, OPTIONAL, SUPPRESS
|
||||
from argparse import FileType, OPTIONAL, ZERO_OR_MORE, SUPPRESS
|
||||
|
||||
from requests.compat import is_windows
|
||||
|
||||
@ -63,8 +63,8 @@ positional.add_argument(
|
||||
''')
|
||||
)
|
||||
positional.add_argument(
|
||||
'items', nargs='*',
|
||||
metavar='REQUEST ITEM',
|
||||
'items', metavar='REQUEST ITEM',
|
||||
nargs=ZERO_OR_MORE,
|
||||
type=KeyValueArgType(*SEP_GROUP_ITEMS),
|
||||
help=_('''
|
||||
A key-value pair whose type is defined by the
|
||||
@ -85,7 +85,9 @@ positional.add_argument(
|
||||
|
||||
content_type = parser.add_argument_group(
|
||||
title='Predefined content types',
|
||||
description=None).add_mutually_exclusive_group(required=False)
|
||||
description=None
|
||||
).add_mutually_exclusive_group(required=False)
|
||||
|
||||
content_type.add_argument(
|
||||
'--json', '-j', action='store_true',
|
||||
help=_('''
|
||||
@ -271,7 +273,7 @@ network.add_argument(
|
||||
''')
|
||||
)
|
||||
network.add_argument(
|
||||
'--allow-redirects', default=False, action='store_true',
|
||||
'--follow', default=False, action='store_true',
|
||||
help=_('''
|
||||
Set this flag if full redirects are allowed
|
||||
(e.g. re-POST-ing of data at new ``Location``)
|
||||
@ -306,7 +308,7 @@ network.add_argument(
|
||||
|
||||
When the server replies with a 4xx (Client Error) or 5xx
|
||||
(Server Error) status code, HTTPie exits with 4 or 5 respectively.
|
||||
If the response is a 3xx (Redirect) and --allow-redirects
|
||||
If the response is a 3xx (Redirect) and --follow
|
||||
hasn't been set, then the exit status is 3.
|
||||
|
||||
Also an error message is written to stderr if stdout is redirected.
|
||||
|
@ -72,7 +72,7 @@ def get_requests_kwargs(args):
|
||||
'auth': credentials,
|
||||
'proxies': dict((p.key, p.value) for p in args.proxy),
|
||||
'files': args.files,
|
||||
'allow_redirects': args.allow_redirects,
|
||||
'allow_redirects': args.follow,
|
||||
'params': args.params,
|
||||
'config': {
|
||||
'base_headers': base_headers
|
||||
|
@ -27,9 +27,9 @@ from .config import CONFIG_DIR
|
||||
from . import EXIT
|
||||
|
||||
|
||||
def get_exist_status(code, allow_redirects=False):
|
||||
def get_exist_status(code, follow=False):
|
||||
"""Translate HTTP status code to exit status."""
|
||||
if 300 <= code <= 399 and not allow_redirects:
|
||||
if 300 <= code <= 399 and not follow:
|
||||
# Redirect
|
||||
return EXIT.ERROR_HTTP_3XX
|
||||
elif 400 <= code <= 499:
|
||||
@ -78,7 +78,7 @@ def main(args=sys.argv[1:], env=Environment()):
|
||||
|
||||
if args.check_status:
|
||||
status = get_exist_status(response.status_code,
|
||||
args.allow_redirects)
|
||||
args.follow)
|
||||
if status and not env.stdout_isatty:
|
||||
error('%s %s', response.raw.status, response.raw.reason)
|
||||
|
||||
|
@ -888,7 +888,7 @@ class ExitStatusTest(BaseTestCase):
|
||||
def test_3xx_check_status_redirects_allowed_exits_0(self):
|
||||
r = http(
|
||||
'--check-status',
|
||||
'--allow-redirects',
|
||||
'--follow',
|
||||
'GET',
|
||||
httpbin('/status/301')
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user