WithHTTPClient overrides the client's HTTP client with the specified one.
(client *http.Client)
| 159 | |
| 160 | // WithHTTPClient overrides the client's HTTP client with the specified one. |
| 161 | func WithHTTPClient(client *http.Client) Opt { |
| 162 | return func(c *clientConfig) error { |
| 163 | if client != nil { |
| 164 | // Make a clone of client so modifications do not affect |
| 165 | // the caller's client. Clone here instead of in New() |
| 166 | // as other options (WithHost) also mutate c.client. |
| 167 | // Cloned clients share the same CookieJar as the |
| 168 | // original. |
| 169 | hc := *client |
| 170 | if ht, ok := hc.Transport.(*http.Transport); ok { |
| 171 | hc.Transport = ht.Clone() |
| 172 | } |
| 173 | c.client = &hc |
| 174 | } |
| 175 | return nil |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | // WithTimeout configures the time limit for requests made by the HTTP client. |
| 180 | func WithTimeout(timeout time.Duration) Opt { |
searching dependent graphs…