Repository navigation
feat: expose Retry-After in Error - #44
Draft
gracehopper-vt wants to merge 1 commit into
Draft
gracehopper-vt wants to merge 1 commit into
gracehopper-vt wants to merge 1 commit into
Conversation
The VirusTotal API is starting to send a Retry-After header with rate-limit and quota-exceeded responses. Parse it (either seconds or an HTTP date) into the new Error.RetryAfter field so callers can wait the right amount of time before retrying. It is zero when the header is not present. Co-authored-by: Oscar Torreno <torreno@google.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
The VirusTotal API is adding a
Retry-Afterheader to rate-limit / quota-exceeded responses (429in API v3). This PR exposes it to vt-go users:Errorgets a newRetryAfter time.Durationfield (json:"-"), set from theRetry-Afterresponse header whenever the API returns an error. It's zero when the header is absent or invalid.parseRetryAfteraccepts both forms allowed by RFC 9110: delta-seconds (Retry-After: 120) and an HTTP date (http.ParseTime).Error()string are unchanged.No automatic retries are added: when a daily or monthly quota is exhausted,
RetryAftercan be hours or days. Once this is released, vt-cli can use it to print a friendlier "retry in X" message.Tests
TestGetObjectOutOfQuotaRetryAfter: a 429 withRetry-After: 120yieldsError{Code: "QuotaExceededError", RetryAfter: 120s}.TestParseRetryAfter: empty, invalid, negative, seconds with whitespace, future HTTP date and past HTTP date.SetResponseHeader.go test ./...passes.gofmtis clean for the touched files; thegofmt -lhits infeed.go,object.goandvt.gopredate this change.