transportForConfig returns a transport for the client, setting the correct Proxy, Dial, and TLSClientConfig if needed. It does not mutate c. It is the caller's responsibility to then use that transport to set the client's httpClient with SetHTTPClient.
(tc *TransportConfig)
| 269 | // It is the caller's responsibility to then use that transport to set |
| 270 | // the client's httpClient with SetHTTPClient. |
| 271 | func (c *Client) transportForConfig(tc *TransportConfig) http.RoundTripper { |
| 272 | if c == nil { |
| 273 | return nil |
| 274 | } |
| 275 | var transport http.RoundTripper |
| 276 | proxy := http.ProxyFromEnvironment |
| 277 | if tc != nil && tc.Proxy != nil { |
| 278 | proxy = tc.Proxy |
| 279 | } |
| 280 | |
| 281 | if c.useHTTP2(tc) { |
| 282 | transport = &http2.Transport{ |
| 283 | DialTLS: c.http2DialTLSFunc(), |
| 284 | } |
| 285 | } else { |
| 286 | transport = &http.Transport{ |
| 287 | DialTLS: c.DialTLSFunc(), |
| 288 | Dial: c.DialFunc(), |
| 289 | Proxy: proxy, |
| 290 | MaxIdleConnsPerHost: maxParallelHTTP_h1, |
| 291 | } |
| 292 | } |
| 293 | httpStats := &httputil.StatsTransport{ |
| 294 | Transport: transport, |
| 295 | } |
| 296 | if tc != nil { |
| 297 | httpStats.VerboseLog = tc.Verbose |
| 298 | } |
| 299 | transport = httpStats |
| 300 | if android.IsChild() { |
| 301 | transport = &android.StatsTransport{Rt: transport} |
| 302 | } |
| 303 | return transport |
| 304 | } |
| 305 | |
| 306 | // HTTPStats returns the client's underlying httputil.StatsTransport, if in use. |
| 307 | // If another transport is being used, nil is returned. |