diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index f0d329c9f..565e6915c 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -184,7 +184,7 @@ func (c *client) ReadData(dst []byte) ([]byte, error) { deadline := time.Now().Add(c.hc.ReadTimeout) req := fasthttp.AcquireRequest() req.SetRequestURI(c.requestURI) - req.SetHost(c.host) + req.Header.SetHost(c.host) // The following `Accept` header has been copied from Prometheus sources. // See https://github.com/prometheus/prometheus/blob/f9d21f10ecd2a343a381044f131ea4e46381ce09/scrape/scrape.go#L532 . // This is needed as a workaround for scraping stupid Java-based servers such as Spring Boot. diff --git a/lib/promscrape/discoveryutils/client.go b/lib/promscrape/discoveryutils/client.go index 293e39831..a26190ee6 100644 --- a/lib/promscrape/discoveryutils/client.go +++ b/lib/promscrape/discoveryutils/client.go @@ -42,6 +42,7 @@ type Client struct { apiServer string + hostPort string authHeader string proxyAuthHeader string sendFullURL bool @@ -127,6 +128,7 @@ func NewClient(apiServer string, ac *promauth.Config, proxyURL proxy.URL, proxyA hc: hc, blockingClient: blockingClient, apiServer: apiServer, + hostPort: hostPort, authHeader: authHeader, proxyAuthHeader: proxyAuthHeader, sendFullURL: sendFullURL, @@ -183,8 +185,8 @@ func (c *Client) getAPIResponseWithParamsAndClient(client *fasthttp.HostClient, req.SetRequestURIBytes(u.FullURI()) } else { req.SetRequestURIBytes(u.RequestURI()) - req.SetHostBytes(u.Host()) } + req.Header.SetHost(c.hostPort) req.Header.Set("Accept-Encoding", "gzip") if c.authHeader != "" { req.Header.Set("Authorization", c.authHeader)