mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #96127 from fonsecas72/header-accept-encoding
HTTP Probe: Removes Accept-Encoding header from http probe
This commit is contained in:
commit
87ed842fa3
@ -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.
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user