RequestHeader for get headers in query
See original GitHub issueHi!, I trying to get header user agent and another params.
I try this:
@GraphQLQuery(name = "getByCode")
public UserDTO getByCode(@GraphQLArgument(name = "code") Date code, @RequestHeader(value="User-Agent") String userAgent) {
UserDTO out = new UserDTO();
return out;
}
And this:
@GraphQLQuery(name = "getByCode")
public UserDTO getByCode(@GraphQLArgument(name = "code") Date code, @ServletRequest request) {
UserDTO out = new UserDTO();
return out;
}
How i can get the headers?
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
how to read header using @Request header in spring-boot ...
1 Answer 1 ... You're right for getting specific headers with @RequestHeader you need to define any of them as new method param...
Read more >Http.RequestHeader (Play 2.8.x)
Checks if the request has the header. Retrieves a single header. The request id. The query string content.
Read more >HTTP headers and common query string parameters for JSON
The JSON API uses the following query string parameters: ... A request header that specifies a user project to bill for access charges...
Read more >HTTP headers - MDN Web Docs - Mozilla
It is a request header that indicates the request's mode to a server. It is a Structured Header whose value is a token...
Read more >Understanding REST Headers and Parameters - SoapUI
You will have to set the request headers when you are sending the request for testing an API and you will have to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
By default, SPQR Spring Boot Starter will use
DefaultGlobalContext
which contains the original request, as you have found out.You can inject the context using
@GraphQLRootContext
:You can also register a custom
ArgumentInjector
that would recognize Spring annotations like@RequestHeader
. Take a look at the context injector for inspiration.SPRQ Spring module will eventually have this built-in, but it’s easily added manually as well.
@dguduguntla Yes, that would be correct. You can also create a custom
ArgumentInjector
to use a custom annotation (e.g.@HttpHeader("Authorization")
) for the same purpose. Or if you’re using Spring, you can use Spring’s@RequestHeader("Authorization")
annotation. Again, this is not built-in (will be soon), but it’s very easy to add yourself. But, since this is about authorization, the best place to implement such concerns is actually in aResolverInterceptor
. See this test for an example.