From 80e8d89665389c9fbd9891383e5f0b3855f3b386 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Fri, 8 Nov 2024 09:01:34 +1100 Subject: [PATCH] fix: only propagate FTL headers --- backend/controller/controller.go | 2 +- internal/rpc/headers/headers.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/controller/controller.go b/backend/controller/controller.go index e290beaa2..caf5fa9ae 100644 --- a/backend/controller/controller.go +++ b/backend/controller/controller.go @@ -853,7 +853,7 @@ func (s *Service) AcquireLease(ctx context.Context, stream *connect.BidiStream[f } func (s *Service) Call(ctx context.Context, req *connect.Request[ftlv1.CallRequest]) (*connect.Response[ftlv1.CallResponse], error) { - return s.callWithRequest(ctx, req, optional.None[model.RequestKey](), optional.None[model.RequestKey](), "") + return s.callWithRequest(ctx, headers.CopyRequest(req), optional.None[model.RequestKey](), optional.None[model.RequestKey](), "") } func (s *Service) PublishEvent(ctx context.Context, req *connect.Request[ftlv1.PublishEventRequest]) (*connect.Response[ftlv1.PublishEventResponse], error) { diff --git a/internal/rpc/headers/headers.go b/internal/rpc/headers/headers.go index f3bb44f1b..779786eae 100644 --- a/internal/rpc/headers/headers.go +++ b/internal/rpc/headers/headers.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" + "connectrpc.com/connect" "github.com/alecthomas/types/optional" "github.com/TBD54566975/ftl/internal/model" @@ -24,6 +25,19 @@ const ( ParentRequestIDHeader = "Ftl-Parent-Request-Id" ) +var headers = []string{DirectRoutingHeader, VerbHeader, RequestIDHeader, ParentRequestIDHeader} + +// CopyRequest creates a new request with the same message as the original, but with only the FTL specific headers +func CopyRequest[T any](req *connect.Request[T]) *connect.Request[T] { + ret := connect.NewRequest(req.Msg) + for _, header := range headers { + if req.Header()[header] != nil { + ret.Header()[header] = req.Header()[header] + } + } + return ret +} + func IsDirectRouted(header http.Header) bool { return header.Get(DirectRoutingHeader) != "" }