diff --git a/lib/Plack/App/Directory.pm b/lib/Plack/App/Directory.pm index 48443ca0..1b0cbf74 100644 --- a/lib/Plack/App/Directory.pm +++ b/lib/Plack/App/Directory.pm @@ -3,6 +3,7 @@ use parent qw(Plack::App::File); use strict; use warnings; use Plack::Util; +use Plack::Util::Accessor 'dir_index'; use HTTP::Date; use Plack::MIME; use DirHandle; @@ -69,6 +70,10 @@ sub serve_path { return $self->return_dir_redirect($env); } + if ($self->dir_index and -f $dir . $self->dir_index) { + return $self->SUPER::serve_path($env, $dir . $self->dir_index); + } + my @files = ([ "../", "Parent Directory", '', '', '' ]); my $dh = DirHandle->new($dir); diff --git a/t/Plack-Middleware/directory.t b/t/Plack-Middleware/directory.t index a2bfb330..cd402f4c 100644 --- a/t/Plack-Middleware/directory.t +++ b/t/Plack-Middleware/directory.t @@ -56,4 +56,26 @@ my %test = ( test_psgi %test; +$handler = Plack::App::Directory->new({ root => 'share', dir_index => 'index.html' }); + +%test = ( + client => sub { + my $cb = shift; + + open my $fh, ">", "share/index.html" or die $!; + print $fh "\n"; + close $fh; + + my $res = $cb->(GET "/"); + is $res->code, 200; + is $res->content, "\n"; + + unlink "share/index.html"; + + }, + app => $handler, +); + +test_psgi %test; + done_testing;