Reputation: 8434
I came for ruby/rails background. I am facing issues to get header attributes of rest call.
In case of rails, I used to write below code to list all requested header attributes.
puts request.headers.inspect
Could any body please suggest me what is the equivalent for Grails ?
Upvotes: 3
Views: 9062
Reputation: 16294
The request object is an instance of the Servlet API's HttpServletRequest interface, so you can use the getHeader
and getHeaderNames
methods
This is an example of how to print all the headers - add it where you can access the request
object (e.g. inside a controller method):
request.getHeaderNames().each {
println(it + ":" + request.getHeader(it))
}
Upvotes: 9
Reputation: 8434
Below is the code, which list all header attributes.
request.headerNames.each{
println it
}
attributes
accept
accept-encoding
content-type
api-key
time-stamp
signature
user-agent
host
Upvotes: 6
Reputation: 7867
Also, remember in Groovy/Grails any getXXX method will treat XXX as a property. So, getHeader and getHeaderNames can be abbreviated to request.header 'someheadername' or request.headerNames
Upvotes: 0
Reputation: 3552
Take a look here. On this page you can find "The request object is an instance of the Servlet API's HttpServletRequest interface". You can use getHeader
and getHeaderNames
methods
Upvotes: 0