Fix #60: Fix undesired behavior when setting Host header
This commit is contained in:
@ -14,6 +14,11 @@ import (
|
|||||||
"github.com/TwinProduction/gatus/client"
|
"github.com/TwinProduction/gatus/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// HostHeader is the name of the header used to specify the host
|
||||||
|
HostHeader = "Host"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrServiceWithNoCondition is the error with which gatus will panic if a service is configured with no conditions
|
// 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")
|
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)
|
request, _ := http.NewRequest(service.Method, service.URL, bodyBuffer)
|
||||||
for k, v := range service.Headers {
|
for k, v := range service.Headers {
|
||||||
request.Header.Set(k, v)
|
request.Header.Set(k, v)
|
||||||
|
if k == HostHeader {
|
||||||
|
request.Host = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,9 @@ func TestService_GetAlertsTriggered(t *testing.T) {
|
|||||||
URL: "https://twinnation.org/health",
|
URL: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
Alerts: []*Alert{{Type: PagerDutyAlert, Enabled: true}},
|
Alerts: []*Alert{{Type: PagerDutyAlert, Enabled: true}},
|
||||||
|
Headers: map[string]string{
|
||||||
|
"Host": "twinnation.org",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
service.ValidateAndSetDefaults()
|
service.ValidateAndSetDefaults()
|
||||||
if service.NumberOfFailuresInARow != 0 {
|
if service.NumberOfFailuresInARow != 0 {
|
||||||
|
Reference in New Issue
Block a user