I’m trying the following code to retrieve a custom HTTP Header but I get null every time. Does anybody have any idea why it may not be working? I’ve searched high and low but cannot figure out why it is not working.
public static Result test()
{
String v = request().getHeader("version");
System.out.println("test" + v);
return ok("success");
}
I’ve tested the code using our iPhone app and restclient.jar too so it doesn’t seem that the problem is the client not sending the header.
Any help will be greatly appreciated!
I banged my head against this one for hours as well. It turns out that Play 2.0 does some odd things with capitalizing HTTP headers. Although I sent a header as “Message-Sender-Uid”, it showed up in Play as “MESSAGE-SENDER-UID”. For some reason Play capitalized the whole header. The solution is to simply look for the all-caps version of your header in the map of headers.
If this fails, then you can always just print all of the headers to the Logger to see if your header is even present.
Something like
in your controller method should work well for this.
Remember to