1 package Catalyst::ActionRole::Scheme;
5 requires 'match', 'match_captures', 'list_extra_info';
7 around ['match','match_captures'] => sub {
8 my ($orig, $self, $ctx, @args) = @_;
9 my $request_scheme = lc($ctx->req->env->{'psgi.url_scheme'});
10 my $match_scheme = lc($self->scheme||'');
12 return $request_scheme eq $match_scheme ? $self->$orig($ctx, @args) : 0;
15 around 'list_extra_info' => sub {
16 my ($orig, $self, @args) = @_;
18 %{ $self->$orig(@args) },
19 Scheme => $self->attributes->{Scheme}[0]||'',
27 Catalyst::ActionRole::Scheme - Match on HTTP Request Scheme
31 package MyApp::Web::Controller::MyController;
33 use base 'Catalyst::Controller';
35 sub is_http :Path(scheme) Scheme(http) Args(0) {
37 Test::More::is $c->action->scheme, 'http';
38 $c->response->body("is_http");
41 sub is_https :Path(scheme) Scheme(https) Args(0) {
43 Test::More::is $c->action->scheme, 'https';
44 $c->response->body("is_https");
51 This is an action role that lets your L<Catalyst::Action> match on the scheme
52 type of the request. Typically this is C<http> or C<https> but other common
53 schemes that L<Catalyst> can handle include C<ws> and C<wss> (web socket and web
56 This also ensures that if you use C<uri_for> on an action that specifies a
57 match scheme, that the generated L<URI> object sets its scheme to that automatically
58 (rather than the scheme of the current request object, which is and remains the
61 For matching purposes, we match strings but the casing is insensitive.
65 This role requires the following methods in the consuming class.
71 Returns 1 if the action matches the existing request and zero if not.
75 This role defines the following methods
81 Around method modifier that return 1 if the scheme matches
83 =head2 list_extra_info
85 Add the scheme declaration if present to the debug screen.
89 Catalyst Contributors, see L<Catalyst>