use HTTP::Headers;
use URI::QueryParam;
use Moose::Util::TypeConstraints;
+use Plack::Loader;
+use Plack::Middleware::Conditional;
+use Plack::Middleware::ReverseProxy;
use namespace::clean -except => 'meta';
</html>
- # Trick IE
+ # Trick IE. Old versions of IE would display their own error page instead
+ # of ours if we'd give it less than 512 bytes.
$c->res->{body} .= ( ' ' x 512 );
# Return 500
my $query = $env->{QUERY_STRING} ? '?' . $env->{QUERY_STRING} : '';
my $uri = $scheme . '://' . $host . '/' . $path . $query;
- $ctx->request->uri( bless \$uri, $uri_class );
+ $ctx->request->uri( (bless \$uri, $uri_class)->canonical );
# set the base URI
# base must end in a slash
=cut
sub run {
- my ($self, $app) = @_;
+ my ($self, $app, $server, @args) = @_;
+ # FIXME - Do something sensible with the options we're passed
+ $server->run($self->build_psgi_app($app, @args));
+}
+
+sub build_psgi_app {
+ my ($self, $app, @args) = @_;
- return sub {
+ my $psgi_app = sub {
my ($env) = @_;
return sub {
$app->handle_request(env => $env);
};
};
+
+ $psgi_app = Plack::Middleware::Conditional->wrap(
+ $psgi_app,
+ condition => sub {
+ my ($env) = @_;
+ return if $app->config->{ignore_frontend_proxy};
+ return $env->{REMOTE_ADDR} eq '127.0.0.1' || $app->config->{using_frontend_proxy};
+ },
+ builder => sub { Plack::Middleware::ReverseProxy->wrap($_[0]) },
+ );
+
+ return $psgi_app;
}
=head2 $self->write($c, $buffer)