From 55b1ae857c9a4420815a2b7abdad8017cd08dc47 Mon Sep 17 00:00:00 2001 From: Ed Robinson Date: Thu, 14 Apr 2016 23:48:32 +0100 Subject: [PATCH] Allow setting the Host header in a httpGet probe Fixes #24288 --- pkg/probe/http/http.go | 3 +++ pkg/probe/http/http_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/probe/http/http.go b/pkg/probe/http/http.go index 9e8b0e1168f..a5fce49fa7f 100644 --- a/pkg/probe/http/http.go +++ b/pkg/probe/http/http.go @@ -64,6 +64,9 @@ func DoHTTPProbe(url *url.URL, headers http.Header, client HTTPGetInterface) (pr return probe.Failure, err.Error(), nil } req.Header = headers + if 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 748abe748ac..88a0ef88839 100644 --- a/pkg/probe/http/http_test.go +++ b/pkg/probe/http/http_test.go @@ -85,6 +85,20 @@ func TestHTTPProbeChecker(t *testing.T) { "X-Muffins-Or-Cupcakes: muffins", }, }, + { + // Echo handler that returns the contents of Host in the body + func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(200) + w.Write([]byte(r.Host)) + }, + http.Header{ + "Host": {"muffins.cupcakes.org"}, + }, + probe.Success, + []string{ + "muffins.cupcakes.org", + }, + }, { handleReq(FailureCode, "fail body"), nil,