Repository navigation
feat(auth): AuthenticatedHttpClient::send, one attempt that returns any status - #192
Merged
Merged
Conversation
…ny status The verb methods go through RetryableHttpClient, which turns a 4xx or 5xx into an error (dropping the body) and retries 5xx, 429 and network errors. A client whose API answers errors with a JSON body, or whose writes must not be sent twice, could not use AuthenticatedHttpClient. send(build) sends once with the bearer token and returns the response whatever its status. On a 401 it invalidates, re-acquires and sends once more, as execute_with_retry does; nothing else is retried. NotAuthenticated surfaces as AuthError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AuthenticatedHttpClient::send(build)sends a request once with the bearer token and returns the response whatever its status.The verb methods (
get,post, …) go throughRetryableHttpClient. That client turns any 4xx or 5xx into ananyhowerror througherror_for_status(), which drops the body. It also retries 5xx, 429 and network errors up to three times. Two kinds of client can't use that:sendkeeps the auth-layer behaviour ofexecute_with_retry. On a 401 it invalidates the token, re-acquires it and sends once more; a second 401 is returned as the response. Nothing else is retried.NotAuthenticated(no cached login) surfaces asAuthErrorinside theanyhow::Error, and nothing is sent.The existing methods are unchanged.
What could leak or be bypassed
Authorizationheader, as before.AccessToken'sDebugstays redacted, andsendlogs nothing.send_returns_an_error_answer_with_its_body_and_does_not_retry_itsends 400, 403, 409, 429, 500 and 503 withexpect(1).send_does_not_retry_a_request_that_got_no_answercovers a refused connection.Tests (
tests/unit/auth_provider.rs)send_returns_an_error_answer_with_its_body_and_does_not_retry_itsend_renews_the_token_once_on_401_and_returns_the_second_answer: token-v1 gets a 401, token-v2 gets a 201; invalidate is called once.send_returns_a_second_401_as_an_answer: two sends, the body is readable.send_surfaces_not_authenticated_and_sends_nothing_without_a_tokensend_does_not_retry_a_request_that_got_no_answerDocs
AuthenticatedHttpClient"skill/references/auth-and-oidc.mdChecks
cargo fmt --all -- --checkcargo clippy --all-features -- -D warningscargo test --all-features --test unit_auth_provider: 15 passed.🤖 Generated with Claude Code