MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / newHTTPClient

Function newHTTPClient

pkg/outputs/http/client.go:31–64  ·  view source on GitHub ↗

newHTTPClient builds a fresh stdlib HTTP client. The HTTP proxy and TLS config is set accordingly if enabled in the HTTP output preferences.

(config Config)

Source from the content-addressed store, hash-verified

29// newHTTPClient builds a fresh stdlib HTTP client. The HTTP proxy and TLS config is set
30// accordingly if enabled in the HTTP output preferences.
31func newHTTPClient(config Config) (*http.Client, error) {
32 tlsConfig, err := tls.MakeConfig(config.TLSCert, config.TLSKey, config.TLSCA, config.TLSInsecureSkipVerify)
33 if err != nil {
34 return nil, fmt.Errorf("invalid TLS config: %v", err)
35 }
36
37 proxy := http.ProxyFromEnvironment
38 if config.ProxyURL != "" {
39 address, err := url.Parse(config.ProxyURL)
40 if err != nil {
41 return nil, fmt.Errorf("invalid HTTP proxy url %q: %w", config.ProxyURL, err)
42 }
43 if config.ProxyUsername != "" && config.ProxyPassword != "" {
44 proxy = http.ProxyURL(&url.URL{
45 Scheme: address.Scheme,
46 User: url.UserPassword(config.ProxyUsername, config.ProxyPassword),
47 Host: config.ProxyURL,
48 })
49 } else {
50 proxy = http.ProxyURL(address)
51 }
52 }
53
54 transport := &http.Transport{
55 TLSClientConfig: tlsConfig,
56 Proxy: proxy,
57 }
58 httpClient := &http.Client{
59 Transport: transport,
60 Timeout: config.Timeout,
61 }
62
63 return httpClient, nil
64}

Callers 3

initHTTPFunction · 0.85
TestHttpPublishFunction · 0.85
TestHttpGzipPublishFunction · 0.85

Calls 1

MakeConfigFunction · 0.92

Tested by 2

TestHttpPublishFunction · 0.68
TestHttpGzipPublishFunction · 0.68