mirror of https://github.com/status-im/consul.git
Correctly forward Host header in healthcheck (#3203)
Host header must be set explicitely on http requests Change-Id: I91a32f0fb1ec3fbc713adf0e10869797e91172c7 Signed-off-by: Grégoire Seux <g.seux@criteo.com>
This commit is contained in:
parent
1f60723610
commit
940b1513a6
|
@ -386,6 +386,10 @@ func (c *CheckHTTP) check() {
|
|||
req.Header = make(http.Header)
|
||||
}
|
||||
|
||||
if host := req.Header.Get("Host"); host != "" {
|
||||
req.Host = host
|
||||
}
|
||||
|
||||
if req.Header.Get("User-Agent") == "" {
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
}
|
||||
|
|
|
@ -213,6 +213,7 @@ func TestCheckHTTP(t *testing.T) {
|
|||
|
||||
// custom header
|
||||
{desc: "custom header", code: 200, header: http.Header{"A": []string{"b", "c"}}, status: api.HealthPassing},
|
||||
{desc: "host header", code: 200, header: http.Header{"Host": []string{"a"}}, status: api.HealthPassing},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
@ -236,6 +237,15 @@ func TestCheckHTTP(t *testing.T) {
|
|||
for k, v := range tt.header {
|
||||
expectedHeader[k] = v
|
||||
}
|
||||
|
||||
// the Host header is in r.Host and not in the headers
|
||||
host := expectedHeader.Get("Host")
|
||||
if host != "" && host != r.Host {
|
||||
w.WriteHeader(999)
|
||||
return
|
||||
}
|
||||
expectedHeader.Del("Host")
|
||||
|
||||
if !reflect.DeepEqual(expectedHeader, r.Header) {
|
||||
w.WriteHeader(999)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue