Subject: | Catalyst::Action::Serialize::JSON does not deal with empty bodies |
If $c->stash->{'rest'} is undef, Catalyst::Action::Serialize::JSON barfs.
This can happen e.g. on an OPTIONS request, which is supposed to have an
empty body - and, in fact, does happen using Catalyst::Action::REST's
default OPTIONS handler when using application/json! In other words, the
default OPTIONS handler doesn't work with application/json.
The right fix, I think, is to have Catalyst::Action::Serialize::JSON
return "" if $c->stash->{$stash_key} is undef.
I've worked around this by putting:
sub end : ActionClass('Serialize') {
my ($self, $c) = @_;
# Catalyst::Action::Serialize::JSON doesn't deal well with empty bodies
# You can get one of these with e.g. OPTIONS requests
if (!defined($c->stash->{'rest'}) {
$c->stash->{'rest'} = {};
}
}
in each of my Controller classes, but that's not great.
Gerv