diff --git a/lib/Dancer2/Core/App.pm b/lib/Dancer2/Core/App.pm index cecd86856..e952c19dd 100644 --- a/lib/Dancer2/Core/App.pm +++ b/lib/Dancer2/Core/App.pm @@ -254,8 +254,6 @@ has context => ( sub setup_context { my ( $self, $ctx ) = @_; - $self->_init_for_context($ctx); - for my $type ( @{ $self->supported_engines } ) { my $attr = "${type}_engine"; my $engine = $self->$attr or next; @@ -419,15 +417,6 @@ sub _init_hooks { ); } -sub _init_for_context { - my ($self) = @_; - - $self->has_request or return; - - $self->request->is_behind_proxy(1) - if $self->setting('behind_proxy'); -} - sub supported_hooks { qw/ core.app.before_request diff --git a/lib/Dancer2/Core/Dispatcher.pm b/lib/Dancer2/Core/Dispatcher.pm index 957144f7d..faf3713c2 100644 --- a/lib/Dancer2/Core/Dispatcher.pm +++ b/lib/Dancer2/Core/Dispatcher.pm @@ -116,8 +116,9 @@ sub build_request { # If we have an app, send the serialization engine my $engine = $app->engine('serializer'); my $request = Dancer2::Core::Request->new( - env => $env, - ( serializer => $engine ) x!! $engine, + env => $env, + is_behind_proxy => Dancer2->runner->config->{'behind_proxy'} || 0, + ( serializer => $engine ) x!! $engine, ); # Log deserialization errors diff --git a/lib/Dancer2/Core/Request.pm b/lib/Dancer2/Core/Request.pm index 51d2847d4..78c5f55cb 100644 --- a/lib/Dancer2/Core/Request.pm +++ b/lib/Dancer2/Core/Request.pm @@ -369,8 +369,9 @@ has body_is_parsed => ( ); has is_behind_proxy => ( - is => 'rw', + is => 'ro', isa => Bool, + lazy => 1, default => sub {0}, ); diff --git a/lib/Dancer2/Core/Role/ConfigReader.pm b/lib/Dancer2/Core/Role/ConfigReader.pm index ce2b96c44..ba8f1c737 100644 --- a/lib/Dancer2/Core/Role/ConfigReader.pm +++ b/lib/Dancer2/Core/Role/ConfigReader.pm @@ -89,6 +89,11 @@ has global_triggers => ( my ( $self, $handler ) = @_; Dancer2->runner->config->{'apphandler'} = $handler; }, + + behind_proxy => sub { + my ( $self, $flag ) = @_; + Dancer2->runner->config->{'behind_proxy'} = $flag; + }, } }, );