X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FActionRole%2FHTTPMethods.pm;h=d0ee99cd2a5420dd670e5c22efc1ea8f9fe8fd8b;hp=a0ab7e294cf050ac4e7425b78f98a7e826764fc8;hb=70949f28d6d56c8c882cd937b9c3be5e04aaba62;hpb=ffca3e960f527321fa30c5ffdfe6ffd2a984af59 diff --git a/lib/Catalyst/ActionRole/HTTPMethods.pm b/lib/Catalyst/ActionRole/HTTPMethods.pm index a0ab7e2..d0ee99c 100644 --- a/lib/Catalyst/ActionRole/HTTPMethods.pm +++ b/lib/Catalyst/ActionRole/HTTPMethods.pm @@ -4,21 +4,7 @@ use Moose::Role; requires 'match', 'match_captures', 'list_extra_info'; -around ['match','match_captures'], sub { - my ($orig, $self, $ctx, @args) = @_; - my $expected = $self->_normalize_expected_http_method($ctx->req); - return $self->_has_expected_http_method($expected) ? - $self->$orig($ctx, @args) : - 0; -}; - -sub _normalize_expected_http_method { - my ($self, $req) = @_; - return $req->header('X-HTTP-Method') || - $req->header('X-HTTP-Method-Override') || - $req->header('X-METHOD-OVERRIDE') || - $req->method; -} +sub allowed_http_methods { @{shift->attributes->{Method}||[]} } sub _has_expected_http_method { my ($self, $expected) = @_; @@ -27,13 +13,20 @@ sub _has_expected_http_method { 1 : 0; } -sub allowed_http_methods { @{shift->attributes->{Method}||[]} } +around ['match','match_captures'] => sub { + my ($orig, $self, $ctx, @args) = @_; + return 0 unless $self->$orig($ctx, @args); -around 'list_extra_info', sub { + my $expected = $ctx->req->method; + warn $expected; + return $self->_has_expected_http_method($expected); +}; + +around 'list_extra_info' => sub { my ($orig, $self, @args) = @_; return { %{ $self->$orig(@args) }, - +{ HTTP_METHODS => [sort $self->allowed_http_methods] } + HTTP_METHODS => [sort $self->allowed_http_methods], }; }; @@ -54,13 +47,13 @@ Catalyst::ActionRole::HTTPMethods - Match on HTTP Methods sub user_base : Chained('/') CaptureArg(0) { ... } - sub get_user : Chained('user_base') Args(1) GET { ... } - sub post_user : Chained('user_base') Args(1) POST { ... } - sub put_user : Chained('user_base') Args(1) PUT { ... } - sub delete_user : Chained('user_base') Args(1) DELETE { ... } - sub head_user : Chained('user_base') Args(1) HEAD { ... } - sub option_user : Chained('user_base') Args(1) OPTION { ... } - sub option_user : Chained('user_base') Args(1) PATCH { ... } + sub get_user : Chained('user_base') Args(1) GET { ... } + sub post_user : Chained('user_base') Args(1) POST { ... } + sub put_user : Chained('user_base') Args(1) PUT { ... } + sub delete_user : Chained('user_base') Args(1) DELETE { ... } + sub head_user : Chained('user_base') Args(1) HEAD { ... } + sub options_user : Chained('user_base') Args(1) OPTIONS { ... } + sub patch_user : Chained('user_base') Args(1) PATCH { ... } sub post_and_put : Chained('user_base') POST PUT Args(1) { ... } @@ -74,25 +67,12 @@ This is an action role that lets your L match on standard HTTP methods, such as GET, POST, etc. Since most web browsers have limited support for rich HTTP Method vocabularies -we also support setting the expected match method via the follow non standard -but widely used http extensions. Our support for these should not be taken as -an endorsement of the technique. Rt is merely a reflection of our desire to -work well with existing systems and common client side tools. - -=over 4 - -=item X-HTTP-Method (Microsoft) - -=item X-HTTP-Method-Override (Google/GData) - -=item X-METHOD-OVERRIDE (IBM) - -=back - -Please note the insanity of overriding a GET request with a DELETE override... -Rational practices suggest that using POST with overrides to emulate PUT and -DELETE can be an acceptable way to deal with client limitations and security -rules on your proxy server. I recommend going no further. +we use L which allows you to 'tunnel' your +request method over POST This works in two ways. You can set an extension +HTTP header C which will contain the value of the +desired request method, or you may set a search query parameter +C. Remember, these only work over HTTP Request type +POST. See L for more. =head1 REQUIRES