Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test + fixed issue in core #1449

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions httpie/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def request_body_read_callback(chunk: bytes):
request_body_read_callback=request_body_read_callback)
force_separator = False
prev_with_body = False
request_message = None

# Process messages as they’re generated
for message in messages:
Expand All @@ -231,14 +232,37 @@ def request_body_read_callback(chunk: bytes):
exit_status = http_status_to_exit_status(http_status=message.status_code, follow=args.follow)
if exit_status != ExitStatus.SUCCESS and (not env.stdout_isatty or args.quiet == 1):
env.log_error(f'HTTP {message.raw.status} {message.raw.reason}', level=LogLevel.WARNING)
write_message(
requests_message=message,
env=env,
output_options=output_options._replace(
body=do_write_body
),
processing_options=processing_options
)
if args.auth_type == 'digest':
if isinstance(message, requests.models.PreparedRequest):
request_message = message
request_output_options = output_options._replace(body=do_write_body)
elif isinstance(message, requests.models.Response):
request_message.headers = message.request.headers
write_message(
requests_message=request_message,
env=env,
output_options=request_output_options,
processing_options=processing_options
)
write_message(
requests_message=message,
env=env,
output_options=output_options._replace(
body=do_write_body
),
processing_options=processing_options
)
else:
continue
else:
write_message(
requests_message=message,
env=env,
output_options=output_options._replace(
body=do_write_body
),
processing_options=processing_options
)
prev_with_body = output_options.body

# Cleanup
Expand Down
7 changes: 7 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,10 @@ def test_ignore_netrc_null_auth():
env=MockEnvironment(),
)
assert isinstance(args.auth, ExplicitNullAuth)


@pytest.mark.parametrize('argument_name', ['--auth-type', '-A'])
def test_digest_auth_auth_header(httpbin_both, argument_name):
r = http(argument_name + '=digest', '--auth=user:password',
'GET', httpbin_both.url + '/digest-auth/auth/user/password', '-v')
assert 'Authorization: Digest username="user", realm="[email protected]"' in r