From 788b7f6d466d301cdb449b44f607e5c581228bd6 Mon Sep 17 00:00:00 2001 From: po-nuvai Date: Mon, 29 Dec 2025 12:37:38 +0530 Subject: [PATCH] Fix --all flag not showing 401 response for digest auth When using digest authentication with the --all flag, the intermediate 401 Unauthorized response was not being displayed. This is because the requests library stores the 401 response in response.history, but HTTPie wasn't yielding those historical responses. This fix checks response.history when --all is used and yields any historical responses (such as the 401 from digest auth challenges). Fixes #1603 --- AUTHORS.md | 1 + httpie/client.py | 7 +++++++ tests/test_auth.py | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 5351307d84..37b4ecd7c9 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -39,3 +39,4 @@ - [Elena Lape](https://github.com/elenalape) - [Rohit Sehgal](https://github.com/r0hi7) - [Bartłomiej Jacak](https://github.com/bartekjacak) +- [POTHIHAI SELVAN S P](https://github.com/po-nuvai) diff --git a/httpie/client.py b/httpie/client.py index a1da284a7c..cf58ab9dcb 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -122,6 +122,13 @@ def collect_messages( ) response_count += 1 + + # Yield historical responses (e.g., 401 from digest auth) with --all + # See: https://github.com/httpie/cli/issues/1603 + if args.all and response.history: + for historical_response in response.history: + yield historical_response + if response.next: if args.max_redirects and response_count == args.max_redirects: raise requests.TooManyRedirects diff --git a/tests/test_auth.py b/tests/test_auth.py index 83423efec0..f21c04070c 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -153,3 +153,24 @@ def test_ignore_netrc_null_auth(): env=MockEnvironment(), ) assert isinstance(args.auth, ExplicitNullAuth) + + +def test_digest_auth_with_all_shows_401(httpbin_both): + """ + Test that --all flag shows the intermediate 401 response + when using digest authentication. + + See: https://github.com/httpie/cli/issues/1603 + """ + r = http( + '--all', + '--auth-type=digest', + '--auth=user:password', + 'GET', + httpbin_both.url + '/digest-auth/auth/user/password' + ) + # Should contain both the 401 and the 200 responses + assert '401 UNAUTHORIZED' in r or '401 Unauthorized' in r + assert HTTP_OK in r + # Verify the authenticated response body is present + assert '"authenticated": true' in r