Fix #60: Fix undesired behavior when setting Host header

This commit is contained in:
TwinProduction 2020-12-18 17:37:03 -05:00
parent b35747bf31
commit ef9ba10e45
2 changed files with 11 additions and 0 deletions

View File

@ -14,6 +14,11 @@ import (
"github.com/TwinProduction/gatus/client"
)
const (
// HostHeader is the name of the header used to specify the host
HostHeader = "Host"
)
var (
// ErrServiceWithNoCondition is the error with which gatus will panic if a service is configured with no conditions
ErrServiceWithNoCondition = errors.New("you must specify at least one condition per service")
@ -216,6 +221,9 @@ func (service *Service) buildHTTPRequest() *http.Request {
request, _ := http.NewRequest(service.Method, service.URL, bodyBuffer)
for k, v := range service.Headers {
request.Header.Set(k, v)
if k == HostHeader {
request.Host = v
}
}
return request
}

View File

@ -96,6 +96,9 @@ func TestService_GetAlertsTriggered(t *testing.T) {
URL: "https://twinnation.org/health",
Conditions: []*Condition{&condition},
Alerts: []*Alert{{Type: PagerDutyAlert, Enabled: true}},
Headers: map[string]string{
"Host": "twinnation.org",
},
}
service.ValidateAndSetDefaults()
if service.NumberOfFailuresInARow != 0 {