Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to forward headers in the unified Gateway? #39

Open
ashwin153 opened this issue Mar 25, 2022 · 1 comment
Open

Is it possible to forward headers in the unified Gateway? #39

ashwin153 opened this issue Mar 25, 2022 · 1 comment

Comments

@ashwin153
Copy link

I would like to forward authentication headers from my unified GraphQL gateway to my backend gRPC services. Normally, I would register a request middleware in Nautilus. Will this library translate the HTTP headers to gRPC metadata?

@cshum
Copy link

cshum commented Apr 20, 2022

For this particular purpose without changing the library, you may try inject HTTP request header using metadata.NewOutgoingContext, through a HTTP middleware:

func authForwardHandler(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		next.ServeHTTP(w, r.WithContext(
			metadata.NewOutgoingContext(r.Context(), map[string][]string{
				"authorization": {r.Header.Get("Authorization")},
			}),
		))
		return
	})
}
...
mux.Handle("/graphql", authForwardHandler(handler.NewDefaultServer(...))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants