Skip to content

Commit 788b7f6

Browse files
committed
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
1 parent 5b604c3 commit 788b7f6

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@
3939
- [Elena Lape](https://github.com/elenalape)
4040
- [Rohit Sehgal](https://github.com/r0hi7)
4141
- [Bartłomiej Jacak](https://github.com/bartekjacak)
42+
- [POTHIHAI SELVAN S P](https://github.com/po-nuvai)

httpie/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ def collect_messages(
122122
)
123123

124124
response_count += 1
125+
126+
# Yield historical responses (e.g., 401 from digest auth) with --all
127+
# See: https://github.com/httpie/cli/issues/1603
128+
if args.all and response.history:
129+
for historical_response in response.history:
130+
yield historical_response
131+
125132
if response.next:
126133
if args.max_redirects and response_count == args.max_redirects:
127134
raise requests.TooManyRedirects

tests/test_auth.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,24 @@ def test_ignore_netrc_null_auth():
153153
env=MockEnvironment(),
154154
)
155155
assert isinstance(args.auth, ExplicitNullAuth)
156+
157+
158+
def test_digest_auth_with_all_shows_401(httpbin_both):
159+
"""
160+
Test that --all flag shows the intermediate 401 response
161+
when using digest authentication.
162+
163+
See: https://github.com/httpie/cli/issues/1603
164+
"""
165+
r = http(
166+
'--all',
167+
'--auth-type=digest',
168+
'--auth=user:password',
169+
'GET',
170+
httpbin_both.url + '/digest-auth/auth/user/password'
171+
)
172+
# Should contain both the 401 and the 200 responses
173+
assert '401 UNAUTHORIZED' in r or '401 Unauthorized' in r
174+
assert HTTP_OK in r
175+
# Verify the authenticated response body is present
176+
assert '"authenticated": true' in r

0 commit comments

Comments
 (0)