MCPcopy Create free account
hub / github.com/prometheus/common / NewClientFromConfig

Function NewClientFromConfig

config/http_config.go:481–493  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

479// given config.HTTPClientConfig and config.HTTPClientOption.
480// The name is used as go-conntrack metric label.
481func 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.

Callers 12

TestNewClientFromConfigFunction · 0.85
TestBasicAuthNoPasswordFunction · 0.85
TestBasicAuthNoUsernameFunction · 0.85
TestBasicUsernameFileFunction · 0.85
TestTLSRoundTripperFunction · 0.85
TestTLSRoundTripperRacesFunction · 0.85

Calls 2

newClientFunction · 0.85

Tested by 12

TestNewClientFromConfigFunction · 0.68
TestBasicAuthNoPasswordFunction · 0.68
TestBasicAuthNoUsernameFunction · 0.68
TestBasicUsernameFileFunction · 0.68
TestTLSRoundTripperFunction · 0.68
TestTLSRoundTripperRacesFunction · 0.68