From dd19fab7c9ffe123528607337d77faacee389ecd Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 4 Apr 2021 01:18:24 +0300 Subject: [PATCH] lib/promscrape: properly send full url in `GET` request via simple HTTP proxy This is a follow-up for a0ae0f86666a75ec57b45eab2429da7ab4a7b250 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1179 --- lib/promscrape/client.go | 2 +- lib/promscrape/discoveryutils/client.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index f0d329c9fc..565e6915c9 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 293e398314..a26190ee63 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)