Skip to content

Commit

Permalink
Remove behind_proxy handling from D2::Core::Request
Browse files Browse the repository at this point in the history
  • Loading branch information
veryrusty committed May 22, 2014
1 parent 5973481 commit 26317cc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 41 deletions.
33 changes: 2 additions & 31 deletions lib/Dancer2/Core/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,8 @@ has body_is_parsed => (
default => sub {0},
);

has is_behind_proxy => (
is => 'rw',
isa => Bool,
default => sub {0},
);

sub host {
my ($self) = @_;

if ( $self->is_behind_proxy ) {
my @hosts = split /\s*,\s*/, $self->env->{HTTP_X_FORWARDED_HOST}, 2;
return $hosts[0];
} else {
return $self->env->{'HTTP_HOST'};
}
return shift->env->{'HTTP_HOST'};
}


Expand Down Expand Up @@ -427,26 +414,10 @@ Return the scheme of the request
=cut


sub scheme {
my ($self) = @_;
my $scheme;
if ( $self->is_behind_proxy ) {
# Note the 'HTTP_' prefix the PSGI spec adds to headers.
$scheme =
$self->env->{'HTTP_X_FORWARDED_PROTOCOL'}
|| $self->env->{'HTTP_X_FORWARDED_PROTO'}
|| $self->env->{'HTTP_FORWARDED_PROTO'}
|| "";
}
return
$scheme
|| $self->env->{'psgi.url_scheme'}
|| $self->env->{'PSGI.URL_SCHEME'}
|| "";
return $_[0]->env->{'psgi.url_scheme'} || "";
}


has serializer => (
is => 'ro',
isa => Maybe( ConsumerOf ['Dancer2::Core::Role::Serializer'] ),
Expand Down
10 changes: 0 additions & 10 deletions t/request.t
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@ sub run_test {
is $req->base, 'http://oddhostname:5000/foo';
}

note "testing behind proxy"; {
my $req = Dancer2::Core::Request->new(
env => $env,
is_behind_proxy => 1
);
is $req->secure, 1;
is $req->host, $env->{HTTP_X_FORWARDED_HOST};
is $req->scheme, 'https';
}

note "testing path, dispatch_path and uri_base"; {
# Base env used for path, dispatch_path and uri_base tests
my $base = {
Expand Down

0 comments on commit 26317cc

Please sign in to comment.