Skip to content

Commit

Permalink
unexpose Client's RoundTrip
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Aug 12, 2022
1 parent f83370e commit 6984f39
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,22 @@ func (c *Client) WrapRoundTripFunc(funcs ...RoundTripWrapperFunc) *Client {
return c.WrapRoundTrip(wrappers...)
}

type roundTripImpl struct {
*Client
}

func (r roundTripImpl) RoundTrip(req *Request) (resp *Response, err error) {
return r.roundTrip(req)
}

// WrapRoundTrip adds a client middleware function that will give the caller
// an opportunity to wrap the underlying http.RoundTripper.
func (c *Client) WrapRoundTrip(wrappers ...RoundTripWrapper) *Client {
if len(wrappers) == 0 {
return c
}
if c.wrappedRoundTrip == nil {
c.wrappedRoundTrip = c
c.wrappedRoundTrip = roundTripImpl{c}
}
for _, w := range wrappers {
c.wrappedRoundTrip = w(c.wrappedRoundTrip)
Expand All @@ -1100,7 +1108,7 @@ func (c *Client) WrapRoundTrip(wrappers ...RoundTripWrapper) *Client {
}

// RoundTrip implements RoundTripper
func (c *Client) RoundTrip(r *Request) (resp *Response, err error) {
func (c *Client) roundTrip(r *Request) (resp *Response, err error) {
resp = &Response{Request: r}

// setup trace
Expand Down Expand Up @@ -1226,7 +1234,7 @@ func (c *Client) do(r *Request) (resp *Response, err error) {
if c.wrappedRoundTrip != nil {
resp, err = c.wrappedRoundTrip.RoundTrip(r)
} else {
resp, err = c.RoundTrip(r)
resp, err = c.roundTrip(r)
}

if r.retryOption == nil || r.RetryAttempt >= r.retryOption.MaxRetries { // absolutely cannot retry.
Expand Down

0 comments on commit 6984f39

Please sign in to comment.