diff --git a/pkg/interceptors/interceptors.go b/pkg/interceptors/interceptors.go index 05cee74aa..f8fe7962e 100644 --- a/pkg/interceptors/interceptors.go +++ b/pkg/interceptors/interceptors.go @@ -32,6 +32,7 @@ import ( const ( CoreInterceptorsHost = "tekton-triggers-core-interceptors" + ContentType = "application/json" ) // Interceptor is the interface that all interceptors implement. @@ -124,6 +125,9 @@ func Execute(ctx context.Context, client *http.Client, req *triggersv1beta1.Inte if err != nil { return nil, err } + + r.Header.Set("Content-Type", ContentType) + res, err := client.Do(r) if err != nil { return nil, err diff --git a/pkg/interceptors/interceptors_test.go b/pkg/interceptors/interceptors_test.go index 2fe0ca660..3472d1423 100644 --- a/pkg/interceptors/interceptors_test.go +++ b/pkg/interceptors/interceptors_test.go @@ -354,6 +354,21 @@ func TestResolveToURL(t *testing.T) { }) } +type localT struct { + T *testing.T +} + +func (t localT) testHeader(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + contentType := r.Header.Get("Content-Type") + if contentType != interceptors.ContentType { + t.T.Fatalf("Header expected to be: %s but got :%s", + interceptors.ContentType, contentType) + } + next.ServeHTTP(w, r) + }) +} + // testServer creates a httptest server with the passed in handler and returns a http.Client that // can be used to talk to these interceptors func testServer(t testing.TB, handler http.Handler, d ...*http.Transport) *http.Client { @@ -427,7 +442,13 @@ func TestExecute(t *testing.T) { if err != nil { t.Fatalf("failed to initialize core interceptors: %v", err) } - httpClient := testServer(t, coreInterceptors) + + lT := localT{ + T: t, + } + + handler := lT.testHeader(coreInterceptors) + httpClient := testServer(t, handler) got, err := interceptors.Execute(context.Background(), httpClient, tc.req, tc.url) if err != nil { t.Fatalf("Execute() unexpected error: %s", err) @@ -446,7 +467,7 @@ func TestExecute_Error(t *testing.T) { "Content-Type": {"application/json"}, }), Context: &triggersv1.TriggerContext{ - EventURL: "http://someurl.com", + EventURL: "http://somurel.com", EventID: "abcde", TriggerID: "namespaces/default/triggers/test-trigger", },