Allow redirections like ::RenderView
Jesse Sheidlower [Wed, 22 Oct 2014 16:04:00 +0000 (11:04 -0500)]
Changes
lib/Catalyst/Action/Serialize.pm

diff --git a/Changes b/Changes
index c174799..72f0f22 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,8 @@
 Revision history for {{$dist->name}}
 
 {{$NEXT}}
+ * Make 3xx status codes skip serialization when there is no data to serialize
+   (Thanks Jesse Sheidlower!)
 
 1.16      2014-09-12 13:21:43-05:00 America/Chicago
  * Switch from JSON to JSON::MaybeXS to get a better choice of JSON parsers.
index b310612..fd36878 100644 (file)
@@ -26,6 +26,15 @@ sub execute {
     return 1 if defined $c->stash->{current_view};
     return 1 if defined $c->stash->{current_view_instance};
 
+    # on 3xx responses, serialize if there's something to
+    # serialize, no-op if not
+    my $stash_key = (
+       $controller->{'serialize'} ?
+           $controller->{'serialize'}->{'stash_key'} :
+                $controller->{'stash_key'}
+           ) || 'rest';
+    return 1 if $c->response->status =~ /^(?:3\d\d)$/ && ! defined $c->stash->{$stash_key};
+
     my ( $sclass, $sarg, $content_type ) =
       $self->_load_content_plugins( "Catalyst::Action::Serialize",
         $controller, $c );