New returns an http.RoundTripper that will provide the authentication or transport level security defined by the provided Config.
(config *Config)
| 28 | // New returns an http.RoundTripper that will provide the authentication |
| 29 | // or transport level security defined by the provided Config. |
| 30 | func New(config *Config) (http.RoundTripper, error) { |
| 31 | // Set transport level security |
| 32 | if config.Transport != nil && (config.HasCA() || config.HasCertAuth() || config.HasCertCallback() || config.TLS.Insecure) { |
| 33 | return nil, fmt.Errorf("using a custom transport with TLS certificate options or the insecure flag is not allowed") |
| 34 | } |
| 35 | |
| 36 | var ( |
| 37 | rt http.RoundTripper |
| 38 | err error |
| 39 | ) |
| 40 | |
| 41 | if config.Transport != nil { |
| 42 | rt = config.Transport |
| 43 | } else { |
| 44 | rt, err = tlsCache.get(config) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return HTTPWrappersForConfig(config, rt) |
| 51 | } |
| 52 | |
| 53 | // TLSConfigFor returns a tls.Config that will provide the transport level security defined |
| 54 | // by the provided Config. Will return nil if no transport level security is requested. |