feat: expose RetryOption for middleware read access (#475) - #515
Merged
Conversation
imroc
approved these changes
Jul 30, 2026
imroc
left a comment
Owner
There was a problem hiding this comment.
Clean PR. Exports RetryOption and adds Request.GetRetryOption() for middleware read access, addressing #475.
Verified locally: go build ./..., go vet ./..., go test ./... all pass (22 packages). CI is green.
Review notes:
- Type rename
retryOption→RetryOptionis safe (was unexported, no external consumers). GetRetryOption()returns the live pointer (not a clone) — documented clearly with the read-only caveat. Reasonable design choice that also allows middleware to adjust retry behavior if needed.- Returns
nilwhen retry is not configured (correct — doesn't create a default like the internalgetRetryOption()does). - 7 new test cases cover nil, request-level, client-level, override, middleware use case, transport errors, and no-report-on-success. Thorough coverage.
- Does not touch
internal/http3/orinternal/http2/.
No blockers. Merging.
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.
Expose RetryOption for middleware read access
Fixes #475.
Summary
This change makes the request retry configuration readable from middleware and other external code, matching the existing public
Request.RetryAttemptfield.RetryOption(formerly unexportedretryOption) withMaxRetries, interval, conditions, and hooks.Request.GetRetryOption()that returns the live retry config, ornilwhen retry is not configured.RetryAttempt >= MaxRetriesdoes not cover early stops fromRetryCondition.Motivation
RetryAttemptwas already readable from middleware, butMaxRetrieslived on an unexportedretryOption. Callers that want to notify on failure only after all retries are exhausted had no public way to read the configured limit.API
Notes:
*RetryOptionis the live option for this request; treat it as read-only unless you intentionally mutate retry behavior.RetryAttempt >= MaxRetriesdetects budget exhaustion only. Retries may also stop earlier when aRetryConditionreturns false.SetRetry*and client-levelSetCommonRetry*continue to clone options onto each request as before.GetRetryOptiondoes not create a default option; only the existing setters do.