Skip to content

Commit

Permalink
fix: strip protocol level headers (#3364)
Browse files Browse the repository at this point in the history
There may be others we need to add here but these two are a good start.
  • Loading branch information
stuartwdouglas authored Nov 9, 2024
1 parent 8efefa6 commit cdcef53
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/rpc/headers/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ const (
// ParentRequestIDHeader is the header used to pass the parent request ID,
// i.e. the publisher that initiated this call.
ParentRequestIDHeader = "Ftl-Parent-Request-Id"

transferEncoding = "Transfer-Encoding"
headerHost = "Host"
)

var headers = []string{DirectRoutingHeader, VerbHeader, RequestIDHeader, ParentRequestIDHeader}
var protocolHeaders = map[string]bool{
headerHost: true,
transferEncoding: true,
}

// 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]
for key, val := range req.Header() {
if !protocolHeaders[key] {
ret.Header()[key] = val
}
}
return ret
Expand Down

0 comments on commit cdcef53

Please sign in to comment.