[Catalyst-commits] r7804 - in
Catalyst-Action-REST/0.60/branches/decouple_deserialize:
lib/Catalyst/Action t
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Mon May 26 18:50:21 BST 2008
Author: lukes
Date: 2008-05-26 18:50:20 +0100 (Mon, 26 May 2008)
New Revision: 7804
Modified:
Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Action/SerializeBase.pm
Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/catalyst-action-serialize-accept.t
Log:
all accepted request types are tried before resorting to default or erroring
Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Action/SerializeBase.pm
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Action/SerializeBase.pm 2008-05-26 15:38:21 UTC (rev 7803)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Action/SerializeBase.pm 2008-05-26 17:50:20 UTC (rev 7804)
@@ -36,8 +36,6 @@
$self->_serialize_plugins( \@plugins );
}
- my $content_type = $c->request->preferred_content_type || '';
-
# Finally, we load the class. If you have a default serializer,
# and we still don't have a content-type that exists in the map,
# we'll use it.
@@ -57,6 +55,8 @@
$map = $config->{'map'};
# If we don't have a handler for our preferred content type, try
# the default
+
+ my ($content_type) = grep { $map->{$_} } @{$c->request->accepted_content_types};
if ( ! exists $map->{$content_type} ) {
if( exists $config->{'default'} ) {
$content_type = $config->{'default'} ;
Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/catalyst-action-serialize-accept.t
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/catalyst-action-serialize-accept.t 2008-05-26 15:38:21 UTC (rev 7803)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/catalyst-action-serialize-accept.t 2008-05-26 17:50:20 UTC (rev 7804)
@@ -18,6 +18,7 @@
'stash_key' => 'rest',
'map' => {
'text/x-yaml' => 'YAML',
+ 'text/x-json' => 'JSON',
'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
'text/broken' => 'Broken',
},
@@ -44,10 +45,11 @@
use strict;
use warnings;
-use Test::More tests => 7;
+use Test::More tests => 10;
use Data::Serializer;
use FindBin;
use Data::Dump qw(dump);
+use JSON::Syck;
use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken");
use Test::Rest;
@@ -72,6 +74,17 @@
is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
}
+{
+ my $at = Test::Rest->new('content_type' => 'text/doesnt-exist');
+ my $req = $at->get(url => '/test');
+ $req->header('Accept', 'text/x-json');
+ my $res = request($req);
+ ok( $res->is_success, 'GET the serialized request succeeded' );
+ my $ret = JSON::Syck::Load($res->content);
+ is( $ret->{lou}, 'is my cat', "Request returned proper data");
+ is( $res->header('Content-type'), 'text/x-json', 'Accept header used if content-type mapping not found')
+}
+
# Make sure we don't get a bogus content-type when using default
# serializer (rt.cpan.org ticket 27949)
{
More information about the Catalyst-commits
mailing list