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

Method Proxy

config/http_config.go:1231–1264  ·  view source on GitHub ↗

Proxy returns the Proxy URL for a request.

()

Source from the content-addressed store, hash-verified

1229
1230// Proxy returns the Proxy URL for a request.
1231func (c *ProxyConfig) Proxy() (fn func(*http.Request) (*url.URL, error)) {
1232 if c == nil {
1233 return nil
1234 }
1235 defer func() {
1236 fn = c.proxyFunc
1237 }()
1238 if c.proxyFunc != nil {
1239 return
1240 }
1241 if c.ProxyFromEnvironment {
1242 proxyFn := httpproxy.FromEnvironment().ProxyFunc()
1243 c.proxyFunc = func(req *http.Request) (*url.URL, error) {
1244 return proxyFn(req.URL)
1245 }
1246 return
1247 }
1248 if c.ProxyURL.URL != nil && c.ProxyURL.URL.String() != "" {
1249 if c.NoProxy == "" {
1250 c.proxyFunc = http.ProxyURL(c.ProxyURL.URL)
1251 return
1252 }
1253 proxy := &httpproxy.Config{
1254 HTTPProxy: c.ProxyURL.String(),
1255 HTTPSProxy: c.ProxyURL.String(),
1256 NoProxy: c.NoProxy,
1257 }
1258 proxyFn := proxy.ProxyFunc()
1259 c.proxyFunc = func(req *http.Request) (*url.URL, error) {
1260 return proxyFn(req.URL)
1261 }
1262 }
1263 return
1264}
1265
1266// ProxyConnectHeader() return the Proxy Connext Headers.
1267func (c *ProxyConfig) GetProxyConnectHeader() http.Header {

Callers 3

TestProxyConfig_ProxyFunction · 0.95
RoundTripMethod · 0.80

Calls 1

StringMethod · 0.65

Tested by 1

TestProxyConfig_ProxyFunction · 0.76