+Wed Jul 04 11:17:20 EDT 2007
+ Fixed 'default' serializer to set a valid Content-Type: header. Fixes
+ RT ticket 27949. Note that behavior has changed -- the default
+ serializer must now be specified as a content-type, not as a plugin
+ name. (dmo@roaringpenguin.com)
+
Thu May 24 14:01:06 PDT 2007 (adam) - Release 0.41
- Moved a bogus $self->class to $c->component($self->class)
+ Moved a bogus $self->class to $c->component($self->class)
Fri Mar 9 14:13:29 PST 2007 (adam) - Release 0.40
- Refactored the Content-Type negotiation to live in Catalyst::Request::REST.
- (drolsky)
- Added some useful debugging. (drolsky)
- Added a View serializer/deserializer, which simply calls the correct
- Catalyst view. ('text/html' => [ 'View', 'TT' ]) (claco, adam)
+ Refactored the Content-Type negotiation to live in Catalyst::Request::REST. (drolsky)
+ Added some useful debugging. (drolsky)
+ Added a View serializer/deserializer, which simply calls the correct
+ Catalyst view. ('text/html' => [ 'View', 'TT' ]) (claco, adam)
Wed Dec 6 00:45:02 PST 2006 (adam) - Release 0.31
Fixed a bug where we would report a blank content-type negotiation.
made. You can ensure that something is always returned by setting the
"default" config option:
- __PACKAGE__->config->{'serialize'}->{'default'} = 'YAML';
+ __PACKAGE__->config->{'serialize'}->{'default'} = 'text/x-yaml';
- Would make it always fall back to YAML.
+ Would make it always fall back to the serializer plugin defined for
+ text/x-yaml.
Implementing new Serialization formats is easy! Contributions are most
welcome! See Catalyst::Action::Serialize and
__PACKAGE__->config(
serialize => {
- 'default' => 'YAML',
+ 'default' => 'text/x-yaml',
'stash_key' => 'rest',
'map' => {
'text/x-yaml' => 'YAML',
__PACKAGE__->config(
serialize => {
- 'default' => 'YAML',
+ 'default' => 'text/x-yaml',
'stash_key' => 'rest',
'map' => {
- 'text/html' => [ 'View', 'TT', ],
+ 'text/html' => [ 'View', 'TT', ],
'text/x-yaml' => 'YAML',
'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
},
=item default
-The default Serialization format. See the next section for
-available options. This is used if a requested content-type
-is not recognized.
+The Content-Type of the default Serialization format. This must be a
+Content-Type associated with a plugin in the "map" section below.
+
+This is used if a requested content-type is not recognized.
=item stash_key
my $sclass = $search_path . "::";
my $sarg;
my $map = $controller->config->{'serialize'}->{'map'};
+
+ # If we don't have a handler for our preferred content type, try
+ # the default
+ if ( ! exists $map->{$content_type} ) {
+ if( exists $controller->config->{'serialize'}->{'default'} ) {
+ $content_type = $controller->config->{'serialize'}->{'default'} ;
+ } else {
+ return $self->_unsupported_media_type($c, $content_type);
+ }
+ }
+
if ( exists( $map->{$content_type} ) ) {
my $mc;
if ( ref( $map->{$content_type} ) eq "ARRAY" ) {
return $self->_unsupported_media_type($c, $content_type);
}
} else {
- if ( exists( $controller->config->{'serialize'}->{'default'} ) ) {
- $sclass .= $controller->config->{'serialize'}->{'default'};
- } else {
- return $self->_unsupported_media_type($c, $content_type);
- }
+ return $self->_unsupported_media_type($c, $content_type);
}
unless ( exists( $self->_loaded_plugins->{$sclass} ) ) {
my $load_class = $sclass;
=back
-By default, L<Catalyst::Controller::REST> will return a C<415 Unsupported Media Type> response if an attempt to use an unsupported content-type is made. You
-can ensure that something is always returned by setting the C<default> config
-option:
+By default, L<Catalyst::Controller::REST> will return a C<415 Unsupported Media Type>
+response if an attempt to use an unsupported content-type is made. You
+can ensure that something is always returned by setting the C<default>
+config option:
- __PACKAGE__->config->{'serialize'}->{'default'} = 'YAML';
+ __PACKAGE__->config->{'serialize'}->{'default'} = 'text/x-yaml';
-Would make it always fall back to YAML.
+Would make it always fall back to the serializer plugin defined for text/x-yaml.
Implementing new Serialization formats is easy! Contributions
are most welcome! See L<Catalyst::Action::Serialize> and
__PACKAGE__->config(
name => 'Test::Catalyst::Action::Serialize',
serialize => {
+ 'default' => 'text/x-yaml',
'stash_key' => 'rest',
'map' => {
'text/x-yaml' => 'YAML',
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 7;
use Data::Serializer;
use FindBin;
use Data::Dump qw(dump);
use_ok 'Catalyst::Test', 'Test::Catalyst::Action::Serialize';
-my $req = $t->get(url => '/test');
-$req->remove_header('Content-Type');
-$req->header('Accept', 'text/x-yaml');
-my $res = request($req);
-ok( $res->is_success, 'GET the serialized request succeeded' );
my $data = <<EOH;
---
lou: is my cat
EOH
-is( $res->content, $data, "Request returned proper data");
+
+{
+ my $req = $t->get(url => '/test');
+ $req->remove_header('Content-Type');
+ $req->header('Accept', 'text/x-yaml');
+ my $res = request($req);
+ ok( $res->is_success, 'GET the serialized request succeeded' );
+ is( $res->content, $data, "Request returned proper data");
+ is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
+}
+
+# Make sure we don't get a bogus content-type when using default
+# serializer (rt.cpan.org ticket 27949)
+{
+ my $req = $t->get(url => '/test');
+ $req->remove_header('Content-Type');
+ $req->header('Accept', '*/*');
+ my $res = request($req);
+ ok( $res->is_success, 'GET the serialized request succeeded' );
+ is( $res->content, $data, "Request returned proper data");
+ is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
+}
1;