'Custom http header not getting push
I am setting a custom http header on bramble a federated graphql gateway server, but it didn't push to my federated service or maybe I'm doing it wrong. If anyone encounter this same issue please educate me, thanks. I using gin for my web framework.
Here's what I done so far,
Im setting this header when calling the api through the gateway server
{
"X-Custom-Header":"SomeValue"
}
and get that from the request
func graphHandler() gin.HandlerFunc {
return func(c *gin.Context) {
v := c.Request.Header.Get("X-Custom-Header")
log.Println("X-Custom-Header value", v)
config := graph.Config{Resolvers: &graph.Resolver{}}
config.Directives.Boundary = func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
return next(ctx)
}
h := handler.NewDefaultServer(graph.NewExecutableSchema(config))
h.ServeHTTP(c.Writer, c.Request)
}
}
func main() {
godotenv.Load()
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
r := gin.Default()
r.POST("/query", graphHandler())
r.GET("/", playgroundHandler())
r.Run(":" + port)
}
gateway configuration (config.json)
{
"services": [
"http://app1:8080/query",
"http://user:8080/query"
],
"gateway-port": 8082,
"private-port": 8083,
"metrics-port": 8084,
"log-level": "debug",
"poll-interval": "5s",
"max-requests-per-query": 50,
"max-client-response-size": 1048576,
"id-field-name": "id",
"plugins":[
{
"name": "cors",
"config": {
"allowed-origins": ["*"],
"allowed-headers": ["x-custom-header"],
"allow-credentials": true,
"max-age": 3600,
"debug": true
}
},
{
"name": "admin-ui"
},
{
"name": "playground"
}
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
