From eee5bc8f9d93beaea1bd8dba1d87a2aacbbaff66 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Fri, 18 Dec 2020 18:39:22 -0500 Subject: [PATCH] Automatically add Content-Type: application/json header for GraphQL requests, unless a different Content-Type is already defined --- core/service.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/service.go b/core/service.go index b0c09b97..45826a30 100644 --- a/core/service.go +++ b/core/service.go @@ -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