Skip to content

Commit

Permalink
fixed bug that prevented conditions to work in embedded applications
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 17, 2012
1 parent ef8a510 commit 1d7c3a0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@
This file documents the revision history for Perl extension Mojolicious.

2.83 2012-04-17
- Fixed bug that prevented conditions to work in embedded applications.
- Fixed small bug in cpanify command.

2.82 2012-04-16
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes/Match.pm
Expand Up @@ -45,7 +45,7 @@ sub match {

# Conditions
if (my $over = $r->over) {
my $conditions = $self->{conditions} ||= $r->root->conditions;
my $conditions = $self->{conditions} ||= $self->root->conditions;
for (my $i = 0; $i < @$over; $i += 2) {
return unless my $condition = $conditions->{$over->[$i]};
return if !$condition->($r, $c, $captures, $over->[$i + 1]);
Expand Down
18 changes: 9 additions & 9 deletions t/mojolicious/embedded_lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 116;
use Test::More tests => 123;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand Down Expand Up @@ -251,7 +251,7 @@ EOF

# GET /host (full external application with domain)
$t->get_ok('/host' => {Host => 'mojolicious.org'})->status_is(200)
->content_is('mojolicious.org');
->header_is('X-Message' => 'it works!')->content_is('mojolicious.org');

# GET / (full external application with domain)
$t->get_ok('/' => {Host => 'mojolicio.us'})->status_is(200)
Expand All @@ -266,7 +266,7 @@ EOF

# GET /host (full external application with domain)
$t->get_ok('/host' => {Host => 'mojolicio.us'})->status_is(200)
->content_is('mojolicio.us');
->header_is('X-Message' => 'it works!')->content_is('mojolicio.us');

# GET / (full external application with domain)
$t->get_ok('/' => {Host => 'kraih.com'})->status_is(200)->content_is(<<'EOF');
Expand All @@ -280,17 +280,17 @@ EOF

# GET /host (full external application with domain)
$t->get_ok('/host' => {Host => 'KRaIH.CoM'})->status_is(200)
->content_is('kraih.com');
->header_is('X-Message' => 'it works!')->content_is('kraih.com');

# GET /host (full external application with wildcard domain)
$t->get_ok('/host' => {Host => 'www.kraih.com'})->status_is(200)
->content_is('www.kraih.com');
->header_is('X-Message' => 'it works!')->content_is('www.kraih.com');

# GET /host (full external application with wildcard domain)
$t->get_ok('/host' => {Host => 'foo.bar.kraih.com'})->status_is(200)
->content_is('foo.bar.kraih.com');
->header_is('X-Message' => 'it works!')->content_is('foo.bar.kraih.com');

# GET /♥/123/host (full external application with a bit of everything)
# GET /♥/123/ (full external application with a bit of everything)
$t->get_ok('/♥/123/' => {Host => 'foo-bar.de'})->status_is(200)
->content_is(<<'EOF');
works!Insecure!Insecure!
Expand All @@ -303,15 +303,15 @@ EOF

# GET /♥/123/host (full external application with a bit of everything)
$t->get_ok('/♥/123/host' => {Host => 'foo-bar.de'})->status_is(200)
->content_is('foo-bar.de');
->header_is('X-Message' => 'it works!')->content_is('foo-bar.de');

# GET /♥/123/echo (full external application with a bit of everything)
$t->get_ok('/♥/123/echo' => {Host => 'foo-bar.de'})->status_is(200)
->content_is('echo: works 3!');

# GET /♥/123/host (full external application with a bit of everything)
$t->get_ok('/♥/123/host' => {Host => 'www.foo-bar.de'})->status_is(200)
->content_is('www.foo-bar.de');
->header_is('X-Message' => 'it works!')->content_is('www.foo-bar.de');

# GET /♥/123/echo (full external application with a bit of everything)
$t->get_ok('/♥/123/echo' => {Host => 'www.foo-bar.de'})->status_is(200)
Expand Down
11 changes: 10 additions & 1 deletion t/mojolicious/external/myapp.pl
Expand Up @@ -11,6 +11,15 @@
# Load plugin
plugin 'Config';

# Message condition
app->routes->add_condition(
message => sub {
my ($r, $c, $captures, $message) = @_;
$c->res->headers->header('X-Message' => $message);
return 1;
}
);

# GET /
get '/' => 'index';

Expand Down Expand Up @@ -39,7 +48,7 @@
};

# GET /host
get '/host' => sub {
get '/host' => (message => 'it works!') => sub {
my $self = shift;
$self->render(text => $self->url_for->base->host);
};
Expand Down

0 comments on commit 1d7c3a0

Please sign in to comment.