Skip to content

Commit

Permalink
fix: only propagate FTL headers (#3358)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Nov 7, 2024
1 parent f2c318c commit c8a2244
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.CopyRequestForForwarding(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) {
Expand Down
14 changes: 14 additions & 0 deletions internal/rpc/headers/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"

"connectrpc.com/connect"
"github.com/alecthomas/types/optional"

"github.com/TBD54566975/ftl/internal/model"
Expand All @@ -24,6 +25,19 @@ const (
ParentRequestIDHeader = "Ftl-Parent-Request-Id"
)

var headers = []string{DirectRoutingHeader, VerbHeader, RequestIDHeader, ParentRequestIDHeader}

// CopyRequestForForwarding creates a new request with the same message as the original, but with only the FTL specific headers
func CopyRequestForForwarding[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) != ""
}
Expand Down

0 comments on commit c8a2244

Please sign in to comment.