diff --git a/pkg/probe/http/http.go b/pkg/probe/http/http.go index c11e03f18ae..5e04ff28be7 100644 --- a/pkg/probe/http/http.go +++ b/pkg/probe/http/http.go @@ -70,6 +70,7 @@ type httpProber struct { // Probe returns a ProbeRunner capable of running an HTTP check. func (pr httpProber) Probe(url *url.URL, headers http.Header, timeout time.Duration) (probe.Result, string, error) { + pr.transport.DisableCompression = true // removes Accept-Encoding header client := &http.Client{ Timeout: timeout, Transport: pr.transport, @@ -104,15 +105,12 @@ func DoHTTPProbe(url *url.URL, headers http.Header, client GetHTTPInterface) (pr if _, ok := headers["Accept"]; !ok { // Accept header was not defined. accept all headers.Set("Accept", "*/*") - } - if headers.Get("Accept") == "" { + } else if headers.Get("Accept") == "" { // Accept header was overridden but is empty. removing headers.Del("Accept") } req.Header = headers - if headers.Get("Host") != "" { - req.Host = headers.Get("Host") - } + req.Host = headers.Get("Host") res, err := client.Do(req) if err != nil { // Convert errors into failures to catch timeouts. diff --git a/pkg/probe/http/http_test.go b/pkg/probe/http/http_test.go index f02dee7c123..b1500348243 100644 --- a/pkg/probe/http/http_test.go +++ b/pkg/probe/http/http_test.go @@ -158,13 +158,37 @@ func TestHTTPProbeChecker(t *testing.T) { handler: headerCounterHandler, reqHeaders: http.Header{}, health: probe.Success, - accBody: "4", + accBody: "3", }, { handler: headerKeysNamesHandler, reqHeaders: http.Header{}, health: probe.Success, - accBody: "Accept\nAccept-Encoding\nConnection\nUser-Agent", + accBody: "Accept\nConnection\nUser-Agent", + }, + { + handler: headerEchoHandler, + reqHeaders: http.Header{ + "Accept-Encoding": {"gzip"}, + }, + health: probe.Success, + accBody: "Accept-Encoding: gzip", + }, + { + handler: headerEchoHandler, + reqHeaders: http.Header{ + "Accept-Encoding": {"foo"}, + }, + health: probe.Success, + accBody: "Accept-Encoding: foo", + }, + { + handler: headerEchoHandler, + reqHeaders: http.Header{ + "Accept-Encoding": {""}, + }, + health: probe.Success, + accBody: "Accept-Encoding: \n", }, { handler: headerEchoHandler,