From 5887421468d56fb0f9e3a9621fd1f4226bf7169e Mon Sep 17 00:00:00 2001 From: Matheus Nogueira Date: Tue, 3 Sep 2024 18:04:24 -0300 Subject: [PATCH] add Host to request in trigger --- agent/workers/trigger/http.go | 4 ++++ agent/workers/trigger/http_test.go | 11 +++++------ server/executor/trigger/http.go | 4 ++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/agent/workers/trigger/http.go b/agent/workers/trigger/http.go index 6c977b04b4..9ccee829ca 100644 --- a/agent/workers/trigger/http.go +++ b/agent/workers/trigger/http.go @@ -75,6 +75,10 @@ func (te *httpTriggerer) Trigger(ctx context.Context, triggerConfig Trigger, opt tReq.Authenticate(req) propagators().Inject(ctx, propagation.HeaderCarrier(req.Header)) + if host := req.Header.Get("Host"); host != "" { + req.Host = host + } + resp, err := client.Do(req.WithContext(ctx)) if err != nil { return response, err diff --git a/agent/workers/trigger/http_test.go b/agent/workers/trigger/http_test.go index 651c5dba1d..d277e37b97 100644 --- a/agent/workers/trigger/http_test.go +++ b/agent/workers/trigger/http_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/kubeshop/tracetest/agent/workers/trigger" - triggerer "github.com/kubeshop/tracetest/agent/workers/trigger" "github.com/kubeshop/tracetest/server/pkg/id" "github.com/stretchr/testify/assert" "go.opentelemetry.io/otel/trace" @@ -56,7 +55,7 @@ func TestTriggerGet(t *testing.T) { }, } - ex := triggerer.HTTP() + ex := trigger.HTTP() resp, err := ex.Trigger(createContext(), triggerConfig, nil) assert.NoError(t, err) @@ -100,7 +99,7 @@ func TestTriggerPost(t *testing.T) { }, } - ex := triggerer.HTTP() + ex := trigger.HTTP() resp, err := ex.Trigger(createContext(), triggerConfig, nil) assert.NoError(t, err) @@ -158,7 +157,7 @@ func TestTriggerPostWithApiKeyAuth(t *testing.T) { }, } - ex := triggerer.HTTP() + ex := trigger.HTTP() resp, err := ex.Trigger(createContext(), triggerConfig, nil) assert.NoError(t, err) @@ -215,7 +214,7 @@ func TestTriggerPostWithBasicAuth(t *testing.T) { }, } - ex := triggerer.HTTP() + ex := trigger.HTTP() resp, err := ex.Trigger(createContext(), triggerConfig, nil) assert.NoError(t, err) @@ -271,7 +270,7 @@ func TestTriggerPostWithBearerAuth(t *testing.T) { }, } - ex := triggerer.HTTP() + ex := trigger.HTTP() resp, err := ex.Trigger(createContext(), triggerConfig, nil) assert.NoError(t, err) diff --git a/server/executor/trigger/http.go b/server/executor/trigger/http.go index e11dba7873..509c245591 100644 --- a/server/executor/trigger/http.go +++ b/server/executor/trigger/http.go @@ -102,6 +102,10 @@ func (te *httpTriggerer) Trigger(ctx context.Context, test test.Test, opts *Trig tReq.Authenticate(req) propagators().Inject(ctx, propagation.HeaderCarrier(req.Header)) + if host := req.Header.Get("Host"); host != "" { + req.Host = host + } + resp, err := client.Do(req.WithContext(ctx)) if err != nil { return response, err