From 2b3d7aeb9bfadebf21176aca287b057168f94cb5 Mon Sep 17 00:00:00 2001 From: Dmitry Latin Date: Fri, 9 Mar 2012 14:38:28 +0400 Subject: [PATCH 1/3] Return requested URI for method when not implemented 3 REST action method Catalyst::Action::REST::_return_not_implemented 4 should return a valid URI for method instead of private method 5 path. --- lib/Catalyst/Action/REST.pm | 3 ++- t/catalyst-action-rest.t | 8 ++++++++ t/lib/Test/Catalyst/Action/REST/Controller/Root.pm | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index f1bf410..f344054 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -158,7 +158,8 @@ sub _return_not_implemented { $c->response->body( "Method " . $c->request->method . " not implemented for " - . $c->uri_for( $method_name ) ); + . $c->req->uri ); + $c->log->debug( "Not implemented for: " . $c->uri_for( $method_name ) ) if $c->debug; } __PACKAGE__->meta->make_immutable; diff --git a/t/catalyst-action-rest.t b/t/catalyst-action-rest.t index 324df80..6f112f2 100644 --- a/t/catalyst-action-rest.t +++ b/t/catalyst-action-rest.t @@ -53,6 +53,14 @@ is( "not_implemented handler had proper response" ); +my $ni_def_res = request( $t->delete( url => '/default/not_implemented' ) ); +is( $ni_def_res->code, 405, "Default not_implemented handler succeeded" ); +like( + $ni_def_res->content, + qr|Method.*?http://.*?/default/not_implemented$|, + "Default not_implemented handler had proper path for response" +); + 1; done_testing; diff --git a/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm b/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm index b42ee24..e0e64a4 100644 --- a/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm +++ b/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm @@ -75,6 +75,9 @@ sub not_implemented_not_implemented { $c->forward('ok'); } +sub default_not_implemented : Path('/default/not_implemented') : ActionClass('REST') { +} + sub not_modified : Local : ActionClass('REST') { } sub not_modified_GET { From a9e5aab63702a80e66bd4b10a20b588dc167fe41 Mon Sep 17 00:00:00 2001 From: Dmitry Latin Date: Fri, 9 Mar 2012 14:40:38 +0400 Subject: [PATCH 2/3] Return request URI for method when not implemented REST action method Catalyst::Action::REST::_return_not_implemented should return a valid URI for method instead of private method path. --- t/catalyst-action-rest.t | 4 ++-- t/lib/Test/Catalyst/Action/REST/Controller/Root.pm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/t/catalyst-action-rest.t b/t/catalyst-action-rest.t index 6f112f2..fd30856 100644 --- a/t/catalyst-action-rest.t +++ b/t/catalyst-action-rest.t @@ -53,11 +53,11 @@ is( "not_implemented handler had proper response" ); -my $ni_def_res = request( $t->delete( url => '/default/not_implemented' ) ); +my $ni_def_res = request( $t->delete( url => '/default/not_implemented/a/b' ) ); is( $ni_def_res->code, 405, "Default not_implemented handler succeeded" ); like( $ni_def_res->content, - qr|Method.*?http://.*?/default/not_implemented$|, + qr|Method.*?http://.*?/default/not_implemented/a/b$|, "Default not_implemented handler had proper path for response" ); diff --git a/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm b/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm index e0e64a4..b7e8b6c 100644 --- a/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm +++ b/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm @@ -75,7 +75,7 @@ sub not_implemented_not_implemented { $c->forward('ok'); } -sub default_not_implemented : Path('/default/not_implemented') : ActionClass('REST') { +sub default_not_implemented : Path('/default/not_implemented') : Args(2) : ActionClass('REST') { } sub not_modified : Local : ActionClass('REST') { } From fbbbd01e5708e64f731e175352fcb25f4b54d979 Mon Sep 17 00:00:00 2001 From: Dmitry Latin Date: Fri, 9 Mar 2012 14:54:14 +0400 Subject: [PATCH 3/3] OPTIONS allowed methods must be uppercase. Fix: OPTIONS request should return only methods in uppercase, e.g.: method_GET - yes method_POST - yes method_post - no --- lib/Catalyst/Action/REST.pm | 2 +- t/lib/Test/Catalyst/Action/REST/Controller/Root.pm | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index f344054..9802d33 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -137,7 +137,7 @@ sub _get_allowed_methods { my ( $self, $controller, $c, $name ) = @_; my $class = ref($controller) ? ref($controller) : $controller; my $methods = Class::Inspector->methods($class); - return map { /^$name\_(.+)$/ } @$methods; + return map { /^$name\_([^[:lower:]]+)$/ } @$methods; }; sub _return_options { diff --git a/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm b/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm index b7e8b6c..4fdde1f 100644 --- a/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm +++ b/t/lib/Test/Catalyst/Action/REST/Controller/Root.pm @@ -58,6 +58,13 @@ sub notreally_GET { $c->forward('ok'); } +sub notreally_TeSt : Local { + my ( $self, $c ) = @_; + + $c->stash->{'entity'} = "notreally test"; + $c->forward('ok'); +} + sub not_implemented : Local : ActionClass('REST') { }