BuildHTTPClient creates an http.Client with the full transport stack: TLS → custom headers → timeout.
(tc TransportConfig)
| 25 | // BuildHTTPClient creates an http.Client with the full transport stack: |
| 26 | // TLS → custom headers → timeout. |
| 27 | func BuildHTTPClient(tc TransportConfig) (*http.Client, error) { |
| 28 | transport, err := BuildTLSTransport( |
| 29 | http.DefaultTransport, |
| 30 | tc.TLSInsecureSkipVerify, |
| 31 | tc.TLSCACertPath, |
| 32 | tc.TLSDisableSystemCAs, |
| 33 | ) |
| 34 | if err != nil { |
| 35 | return nil, err |
| 36 | } |
| 37 | |
| 38 | if len(tc.Headers) > 0 { |
| 39 | transport = &headerTransport{base: transport, headers: tc.Headers} |
| 40 | } |
| 41 | |
| 42 | timeout := defaultTimeout |
| 43 | if tc.Timeout != nil { |
| 44 | timeout = time.Duration(*tc.Timeout) * time.Second |
| 45 | } |
| 46 | |
| 47 | return &http.Client{Timeout: timeout, Transport: transport}, nil |
| 48 | } |
| 49 | |
| 50 | // BearerTokenKey is the context key for storing the bearer token for API key passthrough |
| 51 | var BearerTokenKey = &contextKey{} |