mirror of
https://github.com/httpie/cli.git
synced 2024-11-22 07:43:20 +01:00
Show redirects WIP
This commit is contained in:
parent
dc1371d4d6
commit
c6d4f6cdf6
@ -99,7 +99,6 @@ def main(args=sys.argv[1:], env=Environment(), error=None):
|
||||
return exit_status
|
||||
|
||||
download = None
|
||||
|
||||
try:
|
||||
args = parser.parse_args(args=args, env=env)
|
||||
|
||||
@ -112,7 +111,13 @@ def main(args=sys.argv[1:], env=Environment(), error=None):
|
||||
)
|
||||
download.pre_request(args.headers)
|
||||
|
||||
response = get_response(args, config_dir=env.config.directory)
|
||||
last_response = get_response(args, config_dir=env.config.directory)
|
||||
|
||||
redirect_chain = last_response.history + [last_response]
|
||||
for response in redirect_chain:
|
||||
|
||||
if exit_status != ExitStatus.OK:
|
||||
break
|
||||
|
||||
if args.check_status or download:
|
||||
|
||||
@ -128,25 +133,29 @@ def main(args=sys.argv[1:], env=Environment(), error=None):
|
||||
level='warning')
|
||||
|
||||
write_kwargs = {
|
||||
'stream': build_output_stream(
|
||||
args, env, response.request, response),
|
||||
|
||||
'stream': build_output_stream(args, env,
|
||||
response.request,
|
||||
response),
|
||||
# This will in fact be `stderr` with `--download`
|
||||
'outfile': env.stdout,
|
||||
|
||||
'flush': env.stdout_isatty or args.stream
|
||||
}
|
||||
|
||||
try:
|
||||
|
||||
if env.is_windows and is_py3 and 'colors' in args.prettify:
|
||||
write_with_colors_win_py3(**write_kwargs)
|
||||
else:
|
||||
write(**write_kwargs)
|
||||
except IOError as e:
|
||||
if not traceback and e.errno == errno.EPIPE:
|
||||
# Ignore broken pipes unless --traceback.
|
||||
env.stderr.write('\n')
|
||||
else:
|
||||
raise
|
||||
|
||||
if download and exit_status == ExitStatus.OK:
|
||||
# Response body download.
|
||||
download_stream, download_to = download.start(response)
|
||||
# Last response body download.
|
||||
download_stream, download_to = download.start(last_response)
|
||||
write(
|
||||
stream=download_stream,
|
||||
outfile=download_to,
|
||||
@ -160,12 +169,6 @@ def main(args=sys.argv[1:], env=Environment(), error=None):
|
||||
download.status.downloaded
|
||||
))
|
||||
|
||||
except IOError as e:
|
||||
if not traceback and e.errno == errno.EPIPE:
|
||||
# Ignore broken pipes unless --traceback.
|
||||
env.stderr.write('\n')
|
||||
else:
|
||||
raise
|
||||
except KeyboardInterrupt:
|
||||
if traceback:
|
||||
raise
|
||||
|
@ -22,7 +22,7 @@ SESSION_IGNORED_HEADER_PREFIXES = ['Content-', 'If-']
|
||||
|
||||
def get_response(requests_session, session_name,
|
||||
config_dir, args, read_only=False):
|
||||
"""Like `client.get_response`, but applies permanent
|
||||
"""Like `client.get_responses`, but applies permanent
|
||||
aspects of the session to the request.
|
||||
|
||||
"""
|
||||
@ -30,8 +30,8 @@ def get_response(requests_session, session_name,
|
||||
if os.path.sep in session_name:
|
||||
path = os.path.expanduser(session_name)
|
||||
else:
|
||||
hostname = (args.headers.get('Host', None)
|
||||
or urlsplit(args.url).netloc.split('@')[-1])
|
||||
hostname = (args.headers.get('Host', None) or
|
||||
urlsplit(args.url).netloc.split('@')[-1])
|
||||
if not hostname:
|
||||
# HACK/FIXME: httpie-unixsocket's URLs have no hostname.
|
||||
hostname = 'localhost'
|
||||
|
Loading…
Reference in New Issue
Block a user