X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FActionRole%2FHTTPMethods.pm;h=8b9eef89de46bcc0f1d51c3b313adca0384c5e08;hb=3157d22a51b6dd470bee2b7046b5878277bc64b5;hp=4f2a0d589fb2603786bde840b34c22b659b437c9;hpb=3c0da3ece98e535f1c168bb985980583498894ad;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/ActionRole/HTTPMethods.pm b/lib/Catalyst/ActionRole/HTTPMethods.pm index 4f2a0d5..8b9eef8 100644 --- a/lib/Catalyst/ActionRole/HTTPMethods.pm +++ b/lib/Catalyst/ActionRole/HTTPMethods.pm @@ -4,21 +4,14 @@ use Moose::Role; requires 'match', 'match_captures', 'list_extra_info'; -around ['match','match_captures'], sub { +around ['match','match_captures'] => sub { my ($orig, $self, $ctx, @args) = @_; - my $expected = $self->_normalize_expected_http_method($ctx->req); + my $expected = $ctx->req->method; 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 _has_expected_http_method { my ($self, $expected) = @_; @@ -29,7 +22,13 @@ sub _has_expected_http_method { sub allowed_http_methods { @{shift->attributes->{Method}||[]} } -sub list_extra_info { sort shift->allowed_http_methods } +around 'list_extra_info' => sub { + my ($orig, $self, @args) = @_; + return { + %{ $self->$orig(@args) }, + HTTP_METHODS => [sort $self->allowed_http_methods], + }; +}; 1; @@ -68,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 @@ -116,7 +102,9 @@ normalized as noted above (using X-Method* overrides). =head2 list_extra_info -Returns an array of the allowed HTTP Methods, sorted. +Adds a key => [@values] "HTTP_METHODS" whose value is an ArrayRef of sorted +allowed methods to the ->list_extra_info HashRef. This is used primarily for +debugging output. =head2 _has_expected_http_method ($expected)