From 649da25265aa49baa6c689a1e8da4a64ec7b1a05 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Thu, 31 Oct 2024 18:33:45 +0100 Subject: [PATCH] Expose AlreadyRequested flag in HTTP details of last run (#18) --- client.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index f38fa51..74894ba 100644 --- a/client.go +++ b/client.go @@ -41,8 +41,9 @@ type Client struct { resp *http.Response respBody []byte - attempt int - retryDelays []time.Duration + alreadyRequested bool + attempt int + retryDelays []time.Duration reqHeaders map[string]string reqCookies map[string]string @@ -129,8 +130,9 @@ type HTTPValue struct { OtherResp *http.Response OtherRespBody []byte - Attempt int - RetryDelays []time.Duration + AlreadyRequested bool + Attempt int + RetryDelays []time.Duration } // Details returns HTTP request and response information of last run. @@ -145,8 +147,9 @@ func (c *Client) Details() HTTPValue { OtherResp: c.otherResp, OtherRespBody: c.otherRespBody, - Attempt: c.attempt, - RetryDelays: c.retryDelays, + AlreadyRequested: c.alreadyRequested, + Attempt: c.attempt, + RetryDelays: c.retryDelays, } } @@ -185,6 +188,7 @@ func (c *Client) Reset() *Client { c.otherRespBody = nil c.otherRespExpected = false + c.alreadyRequested = false c.attempt = 0 c.retryDelays = nil @@ -374,6 +378,8 @@ func (c *Client) do() (err error) { //nolint:funlen func (c *Client) expectResp(check func() error) (err error) { if c.resp != nil { + c.alreadyRequested = true + return check() }