return 1 if $c->req->method eq 'HEAD';
return 1 if length( $c->response->body );
return 1 if scalar @{ $c->error };
- return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
+ return 1 if $c->response->status =~ /^(?:204)$/;
my ( $sclass, $sarg, $content_type ) =
$self->_load_content_plugins( "Catalyst::Action::Serialize",
return 1.;
}
+=item status_multiple_choices
+
+Returns a "300 MULTIPLE CHOICES" response. Takes an "entity" to serialize, which should
+provide list of possible locations. Also takes optional "location" for preferred choice.
+
+=cut
+
+sub status_multiple_choices {
+ my $self = shift;
+ my $c = shift;
+ my %p = Params::Validate::validate(
+ @_,
+ {
+ entity => 1,
+ location => { type => SCALAR | OBJECT, optional => 1 },
+ },
+ );
+
+ my $location;
+ if ( ref( $p{'location'} ) ) {
+ $location = $p{'location'}->as_string;
+ } else {
+ $location = $p{'location'};
+ }
+ $c->response->status(300);
+ $c->response->header( 'Location' => $location ) if exists $p{'location'};
+ $self->_set_entity( $c, $p{'entity'} );
+ return 1;
+}
+
=item status_bad_request
Returns a "400 BAD REQUEST" response. Takes a "message" argument
use strict;
use warnings;
-use Test::More tests => 18;
+use Test::More tests => 20;
use YAML::Syck;
use FindBin;
is_deeply Load( $res->content ),
{ error => "Document have been deleted by foo" },
"... status gone message";
+
+ok $res = request( $t->get( url => '/rest/test_status_multiple_choices' ) );
+is $res->code, 300, "... multiple choices";
+
);
}
+sub test_status_multiple_choices : Local {
+ my ( $self, $c ) = @_;
+ $self->status_multiple_choices(
+ $c,
+ location => '/rest/choice1',
+ entity => { choices => [qw(/rest/choice1 /rest/choice2)] }
+ );
+}
+
sub test_status_accepted : Local {
my ( $self, $c ) = @_;
$self->status_accepted( $c, entity => { status => "queued", } );