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