Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
552 changes: 552 additions & 0 deletions router-tests/header_propagation_test.go

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions router-tests/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ func TestForwardHeaders(t *testing.T) {
)

headerRules := config.HeaderRules{
All: config.GlobalHeaderRule{
Request: []config.RequestHeaderRule{
All: &config.GlobalHeaderRule{
Request: []*config.RequestHeaderRule{
{
Operation: config.HeaderRuleOperationPropagate,
Named: headerNameInGlobalRule,
},
},
},
Subgraphs: map[string]config.GlobalHeaderRule{
Subgraphs: map[string]*config.GlobalHeaderRule{
"test1": {
Request: []config.RequestHeaderRule{
Request: []*config.RequestHeaderRule{
{
Operation: config.HeaderRuleOperationPropagate,
Matching: "(?i)^bar.*",
Expand Down Expand Up @@ -246,18 +246,18 @@ func TestForwardRenamedHeaders(t *testing.T) {
)

headerRules := config.HeaderRules{
All: config.GlobalHeaderRule{
Request: []config.RequestHeaderRule{
All: &config.GlobalHeaderRule{
Request: []*config.RequestHeaderRule{
{
Operation: config.HeaderRuleOperationPropagate,
Named: headerNameInGlobalRule,
Rename: headerRenameInGlobalRule,
},
},
},
Subgraphs: map[string]config.GlobalHeaderRule{
Subgraphs: map[string]*config.GlobalHeaderRule{
"test1": {
Request: []config.RequestHeaderRule{
Request: []*config.RequestHeaderRule{
{
Operation: config.HeaderRuleOperationPropagate,
Matching: "(?i)^bar.*",
Expand Down
8 changes: 4 additions & 4 deletions router-tests/singleflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func TestSingleFlightDifferentHeaders(t *testing.T) {
},
RouterOptions: []core.Option{
core.WithHeaderRules(config.HeaderRules{
All: config.GlobalHeaderRule{
Request: []config.RequestHeaderRule{
All: &config.GlobalHeaderRule{
Request: []*config.RequestHeaderRule{
{
Named: "Authorization",
Operation: config.HeaderRuleOperationPropagate,
Expand Down Expand Up @@ -245,8 +245,8 @@ func TestSingleFlightSameHeaders(t *testing.T) {
},
RouterOptions: []core.Option{
core.WithHeaderRules(config.HeaderRules{
All: config.GlobalHeaderRule{
Request: []config.RequestHeaderRule{
All: &config.GlobalHeaderRule{
Request: []*config.RequestHeaderRule{
{
Named: "Authorization",
Operation: config.HeaderRuleOperationPropagate,
Expand Down
3 changes: 2 additions & 1 deletion router-tests/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"errors"
"fmt"
"go.uber.org/zap/zaptest/observer"
"io"
"log"
"math/rand"
Expand All @@ -25,6 +24,8 @@ import (
"testing"
"time"

"go.uber.org/zap/zaptest/observer"

"github.com/wundergraph/cosmo/router/pkg/controlplane/configpoller"

"github.com/nats-io/nats.go/jetstream"
Expand Down
16 changes: 8 additions & 8 deletions router-tests/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ func TestWebSockets(t *testing.T) {
t.Run("subscription with header propagation", func(t *testing.T) {
t.Parallel()
headerRules := config.HeaderRules{
All: config.GlobalHeaderRule{
Request: []config.RequestHeaderRule{
All: &config.GlobalHeaderRule{
Request: []*config.RequestHeaderRule{
{
Operation: config.HeaderRuleOperationPropagate,
Named: "Authorization",
Expand Down Expand Up @@ -652,8 +652,8 @@ func TestWebSockets(t *testing.T) {
t.Run("empty allow lists should allow all headers and query args", func(t *testing.T) {
t.Parallel()
headerRules := config.HeaderRules{
All: config.GlobalHeaderRule{
Request: []config.RequestHeaderRule{
All: &config.GlobalHeaderRule{
Request: []*config.RequestHeaderRule{
{
Operation: config.HeaderRuleOperationPropagate,
Named: "Authorization",
Expand Down Expand Up @@ -795,8 +795,8 @@ func TestWebSockets(t *testing.T) {
t.Run("subscription with header propagation sse subgraph post", func(t *testing.T) {
t.Parallel()
headerRules := config.HeaderRules{
All: config.GlobalHeaderRule{
Request: []config.RequestHeaderRule{
All: &config.GlobalHeaderRule{
Request: []*config.RequestHeaderRule{
{
Operation: config.HeaderRuleOperationPropagate,
Named: "Authorization",
Expand Down Expand Up @@ -910,8 +910,8 @@ func TestWebSockets(t *testing.T) {
t.Run("subscription with header propagation sse subgraph get", func(t *testing.T) {
t.Parallel()
headerRules := config.HeaderRules{
All: config.GlobalHeaderRule{
Request: []config.RequestHeaderRule{
All: &config.GlobalHeaderRule{
Request: []*config.RequestHeaderRule{
{
Operation: config.HeaderRuleOperationPropagate,
Named: "Authorization",
Expand Down
4 changes: 2 additions & 2 deletions router/core/factoryresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (l *Loader) LoadInternedString(engineConfig *nodev1.EngineConfiguration, st

type RouterEngineConfiguration struct {
Execution config.EngineExecutionConfiguration
Headers config.HeaderRules
Headers *config.HeaderRules
Events config.EventsConfiguration
SubgraphErrorPropagation config.SubgraphErrorPropagationConfiguration
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func (l *Loader) Load(engineConfig *nodev1.EngineConfiguration, subgraphs []*nod
}
}

dataSourceRules := FetchURLRules(&routerEngineConfig.Headers, subgraphs, subscriptionUrl)
dataSourceRules := FetchURLRules(routerEngineConfig.Headers, subgraphs, subscriptionUrl)
forwardedClientHeaders, forwardedClientRegexps, err := PropagatedHeaders(dataSourceRules)
if err != nil {
return nil, fmt.Errorf("error parsing header rules for data source %s: %w", in.Id, err)
Expand Down
1 change: 1 addition & 0 deletions router/core/graph_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ func (s *graphServer) buildGraphMux(ctx context.Context,
EnableExecutionPlanCacheResponseHeader: s.engineExecutionConfiguration.EnableExecutionPlanCacheResponseHeader,
EnablePersistedOperationCacheResponseHeader: s.engineExecutionConfiguration.Debug.EnablePersistedOperationsCacheResponseHeader,
EnableNormalizationCacheResponseHeader: s.engineExecutionConfiguration.Debug.EnableNormalizationCacheResponseHeader,
EnableResponseHeaderPropagation: s.headerRules != nil,
WebSocketStats: s.websocketStats,
TracerProvider: s.tracerProvider,
Authorizer: NewCosmoAuthorizer(authorizerOptions),
Expand Down
8 changes: 7 additions & 1 deletion router/core/graphql_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type HandlerOptions struct {
EnableExecutionPlanCacheResponseHeader bool
EnablePersistedOperationCacheResponseHeader bool
EnableNormalizationCacheResponseHeader bool
EnableResponseHeaderPropagation bool
WebSocketStats WebSocketsStatistics
TracerProvider trace.TracerProvider
Authorizer *CosmoAuthorizer
Expand All @@ -96,6 +97,7 @@ func NewGraphQLHandler(opts HandlerOptions) *GraphQLHandler {
enableExecutionPlanCacheResponseHeader: opts.EnableExecutionPlanCacheResponseHeader,
enablePersistedOperationCacheResponseHeader: opts.EnablePersistedOperationCacheResponseHeader,
enableNormalizationCacheResponseHeader: opts.EnableNormalizationCacheResponseHeader,
enableResponseHeaderPropagation: opts.EnableResponseHeaderPropagation,
websocketStats: opts.WebSocketStats,
tracer: opts.TracerProvider.Tracer(
"wundergraph/cosmo/router/graphql_handler",
Expand Down Expand Up @@ -135,6 +137,7 @@ type GraphQLHandler struct {
enableExecutionPlanCacheResponseHeader bool
enablePersistedOperationCacheResponseHeader bool
enableNormalizationCacheResponseHeader bool
enableResponseHeaderPropagation bool
}

func (h *GraphQLHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -182,7 +185,10 @@ func (h *GraphQLHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case *plan.SynchronousResponsePlan:
w.Header().Set("Content-Type", "application/json")
h.setDebugCacheHeaders(w, operationCtx)
resp, err := h.executor.Resolver.ResolveGraphQLResponse(ctx, p.Response, nil, w)
if h.enableResponseHeaderPropagation {
Comment thread
StarpTech marked this conversation as resolved.
ctx = WithResponseHeaderPropagation(ctx)
}
resp, err := h.executor.Resolver.ResolveGraphQLResponse(ctx, p.Response, nil, HeaderPropagationWriter(w, ctx.Context()))
if err != nil {
requestLogger.Error("unable to resolve response", zap.Error(err))
trackResponseError(ctx.Context(), err)
Expand Down
Loading