NewClientFromConfig returns a new HTTP client configured for the given config.HTTPClientConfig and config.HTTPClientOption. The name is used as go-conntrack metric label.
(cfg HTTPClientConfig, name string, optFuncs ...HTTPClientOption)
| 479 | // given config.HTTPClientConfig and config.HTTPClientOption. |
| 480 | // The name is used as go-conntrack metric label. |
| 481 | func NewClientFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HTTPClientOption) (*http.Client, error) { |
| 482 | rt, err := NewRoundTripperFromConfig(cfg, name, optFuncs...) |
| 483 | if err != nil { |
| 484 | return nil, err |
| 485 | } |
| 486 | client := newClient(rt) |
| 487 | if !cfg.FollowRedirects { |
| 488 | client.CheckRedirect = func(*http.Request, []*http.Request) error { |
| 489 | return http.ErrUseLastResponse |
| 490 | } |
| 491 | } |
| 492 | return client, nil |
| 493 | } |
| 494 | |
| 495 | // NewRoundTripperFromConfig returns a new HTTP RoundTripper configured for the |
| 496 | // given config.HTTPClientConfig and config.HTTPClientOption. |