[Jifty-commit] r3514 - in jifty/trunk: lib/Jifty
t/TestApp/lib/TestApp t/TestApp/share/web/templates/dispatch
t/TestApp/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Jun 17 16:53:51 EDT 2007
Author: trs
Date: Sun Jun 17 16:53:50 2007
New Revision: 3514
Added:
jifty/trunk/t/TestApp/share/web/templates/dispatch/protocol
jifty/trunk/t/TestApp/t/02-dispatch-http.t
jifty/trunk/t/TestApp/t/02-dispatch-https.t
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Dispatcher.pm
jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
Log:
r24679 at zot: tom | 2007-06-16 15:20:42 -0400
HTTPS and HTTP adjectives for dispatcher rules
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Sun Jun 17 16:53:50 2007
@@ -160,7 +160,7 @@
All wildcards in the C<$match> string becomes capturing regex patterns. You
can also pass in an array reference of matches, or a regex pattern.
-The C<$match> string may be qualified with a HTTP method name, such as
+The C<$match> string may be qualified with a HTTP method name or protocol, such as
=over
@@ -176,6 +176,10 @@
=item HEAD
+=item HTTPS
+
+=item HTTP
+
=back
=head2 on $match => $rule
@@ -263,6 +267,8 @@
GET POST PUT HEAD DELETE OPTIONS
+ HTTPS HTTP
+
plugin
get next_rule last_rule
@@ -300,6 +306,9 @@
sub DELETE ($) { _qualify method => @_ }
sub OPTIONS ($) { _qualify method => @_ }
+sub HTTPS ($) { _qualify https => @_ }
+sub HTTP ($) { _qualify http => @_ }
+
sub plugin ($) { return { plugin => @_ } }
our $CURRENT_STAGE;
@@ -929,6 +938,30 @@
lc( $ENV{REQUEST_METHOD} ) eq lc($method);
}
+=head2 _match_https
+
+Returns true if the current request is under SSL.
+
+=cut
+
+sub _match_https {
+ my $self = shift;
+ $self->log->debug("Matching request against HTTPS");
+ return exists $ENV{HTTPS} ? 1 : 0;
+}
+
+=head2 _match_http
+
+Returns true if the current request is not under SSL.
+
+=cut
+
+sub _match_http {
+ my $self = shift;
+ $self->log->debug("Matching request against HTTP");
+ return exists $ENV{HTTPS} ? 0 : 1;
+}
+
sub _match_plugin {
my ( $self, $plugin ) = @_;
warn "Deferred check shouldn't happen";
Modified: jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm (original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm Sun Jun 17 16:53:50 2007
@@ -82,4 +82,16 @@
}
};
+on HTTPS '/dispatch/protocol' => run {
+ set content => 'HTTPS';
+};
+
+on HTTP '/dispatch/protocol' => run {
+ set content => 'NOT HTTPS';
+};
+
+on '/dispatch/protocol' => run {
+ set footer => 'normal';
+};
+
1;
Added: jifty/trunk/t/TestApp/share/web/templates/dispatch/protocol
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/share/web/templates/dispatch/protocol Sun Jun 17 16:53:50 2007
@@ -0,0 +1,3 @@
+<&| /_elements/wrapper, title => "Test of protocol adjectives" &>
+<% Jifty::YAML::Dump(\%ARGS) %>
+</&>
Added: jifty/trunk/t/TestApp/t/02-dispatch-http.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/02-dispatch-http.t Sun Jun 17 16:53:50 2007
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+# Just in case
+BEGIN { delete $ENV{HTTPS}; }
+
+use lib 't/lib';
+use Jifty::SubTest;
+use Jifty::Test tests => 5;
+use Jifty::Test::WWW::Mechanize;
+
+my $server = Jifty::Test->make_server;
+
+isa_ok($server, 'Jifty::Server');
+
+my $URL = $server->started_ok;
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+$mech->get_ok("$URL/dispatch/protocol", "Got /dispatch/protocol");
+$mech->content_contains("NOT HTTPS");
+$mech->content_contains("normal");
+
Added: jifty/trunk/t/TestApp/t/02-dispatch-https.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/02-dispatch-https.t Sun Jun 17 16:53:50 2007
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+BEGIN { $ENV{HTTPS} = 1; }
+
+use lib 't/lib';
+use Jifty::SubTest;
+use Jifty::Test tests => 6;
+use Jifty::Test::WWW::Mechanize;
+
+my $server = Jifty::Test->make_server;
+
+isa_ok($server, 'Jifty::Server');
+
+my $URL = $server->started_ok;
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+$mech->get_ok("$URL/dispatch/protocol", "Got /dispatch/protocol");
+$mech->content_contains("HTTPS");
+$mech->content_lacks("NOT");
+$mech->content_contains("normal");
+
+
More information about the Jifty-commit
mailing list