Route matching on URL Scheme

Matching for HTTP:, HTTPS: (or WS:, WSS:)


The following controller matches either http://localhost/root/scheme or https://localhost/root/scheme and returns the expected body content:

    package MyApp::Controller::Root;

    use base 'Catalyst::Controller';

    sub is_http :Path(scheme) Scheme(http) Args(0) {
      my ($self, $c) = @_;
      Test::More::is $c->action->scheme, 'http';

    sub is_https :Path(scheme) Scheme(https) Args(0)  {
      my ($self, $c) = @_;
      Test::More::is $c->action->scheme, 'https';

uri_for has had additional smarts built into it to automatically know if an action or action chain has a scheme associated with it:

    # Returns http://localhost/root/scheme
    warn $c->uri_for( $c->controller('Root')->action_for('is_http'));

    # Returns https://localhost/root/scheme
    warn $c->uri_for( $c->controller('Root')->action_for('is_http'));


You often need to have your application perform one set of actions or another depending in the incoming request scheme. You might for example have part of your application secure under https but the rest of it using http. This new action attribute allows you to match as required.

You may use this for all recognized URI Scheme (including websockets schemes).

Lastly, we've improved how uri_for works so that if it notices the specified route has an attribute Scheme it will create the correct URL.


We continue to enhance Catalyst's ability to match different incoming requests as well as trying to make it easier to just do the right thing.


John Napiorkowski