Automatically add Content-Type: application/json header for GraphQL requests, unless a different Content-Type is already defined

This commit is contained in:
TwinProduction 2020-12-18 18:39:22 -05:00
parent 4d186c6e71
commit eee5bc8f9d

View File

@ -17,6 +17,9 @@ import (
const (
// HostHeader is the name of the header used to specify the host
HostHeader = "Host"
// ContentTypeHeader is the name of the header used to specify the content type
ContentTypeHeader = "Content-Type"
)
var (
@ -87,6 +90,11 @@ func (service *Service) ValidateAndSetDefaults() {
if len(service.Headers) == 0 {
service.Headers = make(map[string]string)
}
// Automatically add "Content-Type: application/json" header if there's no Content-Type set
// and service.GraphQL is set to true
if _, contentTypeHeaderExists := service.Headers[ContentTypeHeader]; !contentTypeHeaderExists && service.GraphQL {
service.Headers[ContentTypeHeader] = "application/json"
}
for _, alert := range service.Alerts {
if alert.FailureThreshold <= 0 {
alert.FailureThreshold = 3