[Catalyst-commits] r8060 - in Catalyst-Action-REST/0.60/trunk: .
lib/Catalyst/Action t
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Mon Jun 30 19:50:30 BST 2008
Author: lukes
Date: 2008-06-30 19:50:29 +0100 (Mon, 30 Jun 2008)
New Revision: 8060
Modified:
Catalyst-Action-REST/0.60/trunk/
Catalyst-Action-REST/0.60/trunk/lib/Catalyst/Action/SerializeBase.pm
Catalyst-Action-REST/0.60/trunk/t/catalyst-action-serialize-accept.t
Log:
r7361 at luke-mbp (orig r7801): lukes | 2008-05-26 15:09:41 +0100
new branch for decoupling Catalyst::Action::Serialize from REST
r7362 at luke-mbp (orig r7804): lukes | 2008-05-26 18:50:20 +0100
all accepted request types are tried before resorting to default or erroring
r7363 at luke-mbp (orig r7805): lukes | 2008-05-26 18:53:17 +0100
sanified code surrounding recent change
r8416 at luke-mbp (orig r8059): lukes | 2008-06-30 19:50:17 +0100
fixed stuff after pull
Property changes on: Catalyst-Action-REST/0.60/trunk
___________________________________________________________________
Name: svk:merge
- 30504762-a21f-0410-86fe-fb543316e637:/local/Catalyst-Action-REST:70
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Action-REST/0.50/trunk:7341
58586828-bfeb-4a8b-ac3c-3302daf284f8:/local/Catalyst-Action-REST/0.60/trunk:1682
+ 30504762-a21f-0410-86fe-fb543316e637:/local/Catalyst-Action-REST:70
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Action-REST/0.50/trunk:7341
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Action-REST/0.60/branches/decouple_deserialize:8059
58586828-bfeb-4a8b-ac3c-3302daf284f8:/local/Catalyst-Action-REST/0.60/trunk:1682
Modified: Catalyst-Action-REST/0.60/trunk/lib/Catalyst/Action/SerializeBase.pm
===================================================================
--- Catalyst-Action-REST/0.60/trunk/lib/Catalyst/Action/SerializeBase.pm 2008-06-30 18:50:17 UTC (rev 8059)
+++ Catalyst-Action-REST/0.60/trunk/lib/Catalyst/Action/SerializeBase.pm 2008-06-30 18:50:29 UTC (rev 8060)
@@ -36,14 +36,6 @@
$self->_serialize_plugins( \@plugins );
}
- my $content_type = $c->request->preferred_content_type || '';
-
- # carp about old text/x-json
- if ($content_type eq 'text/x-json') {
- $c->log->info('Using deprecated text/x-json content-type.');
- $c->log->info('Use application/json instead!');
- }
-
# 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.
@@ -63,7 +55,10 @@
$map = $config->{'map'};
# If we don't have a handler for our preferred content type, try
# the default
- if ( ! exists $map->{$content_type} ) {
+
+ my ($content_type) = grep { $map->{$_} } @{$c->request->accepted_content_types};
+
+ unless ( defined $content_type ) {
if( exists $config->{'default'} ) {
$content_type = $config->{'default'} ;
} else {
@@ -71,6 +66,12 @@
}
}
+ # carp about old text/x-json
+ if ($content_type eq 'text/x-json') {
+ $c->log->info('Using deprecated text/x-json content-type.');
+ $c->log->info('Use application/json instead!');
+ }
+
if ( exists( $map->{$content_type} ) ) {
my $mc;
if ( ref( $map->{$content_type} ) eq "ARRAY" ) {
Modified: Catalyst-Action-REST/0.60/trunk/t/catalyst-action-serialize-accept.t
===================================================================
--- Catalyst-Action-REST/0.60/trunk/t/catalyst-action-serialize-accept.t 2008-06-30 18:50:17 UTC (rev 8059)
+++ Catalyst-Action-REST/0.60/trunk/t/catalyst-action-serialize-accept.t 2008-06-30 18:50:29 UTC (rev 8060)
@@ -18,6 +18,7 @@
'stash_key' => 'rest',
'map' => {
'text/x-yaml' => 'YAML',
+ 'application/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', 'application/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'), 'application/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