Subject: | Serializer issue: params hash not populated when the Content-Type is a supported media type with additional parameters |
Date: | Mon, 24 May 2010 21:23:38 +0100 |
To: | bug-Dancer [...] rt.cpan.org |
From: | Richard Evans <richard_david_evans [...] yahoo.co.uk> |
Hello
Dancer-1.1803
I've just started using Dancer as a backend for Sproutcore, and am using Dancer's JSON serializer for automatic (de)serialization.
In some cases the params hash is not populated on POSTs, despite firebug showing valid JSON requests.
Looking at the requests being sent, depending on the context, either of the following Content-Types are set:
* application/json
* application/json; charset=UTF-8
The first case works correctly, it's when the "charset" parameter is present that the params hash is unpopulated.
From a quick glance, I think the issue is in Dancer::Serializer::Abstract::support_content_type()
sub support_content_type {
my ($self, $ct) = @_;
return $ct eq $self->content_type;
}
I'm guessing Dancer is comparing "application/json" to "application/json; charset=UTF-8" and therefore returning false, so it may need to split on the ";" or use a regexp. I think this should also be a case insensitive comparison, according to rfc2616.
To reproduce:
set serializer => 'JSON';
post '/test' => sub {
return { test_value => params->{test_value} };
};
$ curl -H "Content-Type: application/json" -X POST http://localhost:3000/test -d '{"test_value":"set"}'
{"test_value":"set"}
$ curl -H "Content-Type: APPLICATION/JSON" -X POST http://localhost:3000/test -d '{"test_value":"set"}'
{"test_value":null}
$ curl -H "Content-Type: application/json; charset=UTF-8" -X POST http://localhost:3000/test -d '{"test_value":"set"}'
{"test_value":null}
Many thanks for all the work you're putting into Dancer, great stuff!
Richard Evans
--
richard_david_evans@yahoo.co.uk