feat: capture HTTP Retry-After header in Error::retry_delay() (#21) #22
Reference in New Issue
Block a user
Delete Branch "feat/retry-after-header"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #21
Changes
src/client.rs:error_for_statusreads theRetry-Afterheader before it consumes the body, for every non-success response.parse_retry_afteraccepts only the delay-seconds form (1*DIGIT), so values such as+30are rejected.src/error.rs:Error::HttpStatushas a newretry_after: Option<Duration>field, andError::retry_delay()returns it.src/types/error.rs:VertexApiErrorhas a newretry_afterfield. Serde skips it because it isn't in the JSON body; the client fills it in.VertexApiError::retry_delay()usesgoogle.rpc.RetryInfowhen present and falls back toretry_after. This keeps the header on the common shape: a JSON 429 that has noRetryInfo.src/client_tests.rs: the mock server and client setup is now shared through themock_clientandhttp_responsehelpers, instead of being copied into every test.Breaking changes
Error::HttpStatusandVertexApiErroreach have a new public field. Code that destructures them without.., or builds them with a struct literal, needs updating. The crate is already at 0.2.0 and unreleased, so I didn't bump the version again.Not included
Retry-After: Wed, 21 Oct 2015 07:28:00 GMT): it returnsNone. Supporting it would mean adding a date-parsing dependency, and the issue marked it optional.Tests
Retry-After: 30givesHttpStatus { retry_after: Some(30s) }.RetryInfogivesVertexErrorwithretry_after: Some(30s).RetryInfo(37s) andRetry-After: 30gives 37s.None.30and0parse. An HTTP-date,soon,-1,+30,1.5and an empty value giveNone.retry_delay(): covered for the fallback and forRetryInfotaking precedence, on bothVertexApiErrorandError.cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass locally.