docroot => $docroot,
index => $index,
autoindex => $opt{autoindex},
+ # not using Plack::MIME->set_fallback since we can have
+ # multiple WwwStatic instances with a different default
+ default_type => $opt{default_type} //
+ 'application/octet-stream',
style => $style // \$STYLE,
}, $class;
}
sprintf('%lu', $size).$suffix;
}
+sub file_response ($$$) {
+ my ($self, $env, $fs_path) = @_;
+ response $env, [], $fs_path,
+ Plack::MIME->mime_type($fs_path) // $self->{default_type};
+
+}
+
# by default, this returns "index.html" if it exists for a given directory
# It'll generate a directory listing, (autoindex).
# May be disabled by setting autoindex => 0
my ($self, $env, $fs_path) = @_;
if (my $index = $self->{'index'}) { # serve index.html or similar
for my $html (@$index) {
- my $p = $fs_path . $html;
- my $res = response($env, [], $p);
+ my $res = file_response($self, $env, $fs_path.$html);
return $res if $res->[0] != 404;
}
}
my $fs_path = join('/', $self->{docroot}, @parts);
return dir_response($self, $env, $fs_path) if $parts[-1] eq '';
- my $res = response($env, [], $fs_path);
+ my $res = file_response($self, $env, $fs_path);
$res->[0] == 404 && -d $fs_path ? redirect_slash($env) : $res;
}