MCPcopy
hub / github.com/perkeep/perkeep / transportForConfig

Method transportForConfig

pkg/client/client.go:271–304  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

269// It is the caller's responsibility to then use that transport to set
270// the client's httpClient with SetHTTPClient.
271func (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.

Callers 2

TestTransportSetupFunction · 0.95
setDefaultHTTPClientMethod · 0.95

Calls 5

useHTTP2Method · 0.95
http2DialTLSFuncMethod · 0.95
DialTLSFuncMethod · 0.95
DialFuncMethod · 0.95
IsChildFunction · 0.92

Tested by 1

TestTransportSetupFunction · 0.76