Commit ed823b9e authored by Xavier Guimard's avatar Xavier Guimard

Restore headers with Apache (#1044)

parent 75ffa010
...@@ -4,12 +4,8 @@ sub hello { ...@@ -4,12 +4,8 @@ sub hello {
return 'Hello'; return 'Hello';
} }
sub get_uri {
return $_[0];
}
sub get_additional_arg { sub get_additional_arg {
return $_[1]; return $_[0];
} }
1; 1;
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
"cfgNum": "1", "cfgNum": "1",
"cfgVersion": "2.0.0", "cfgVersion": "2.0.0",
"cookieName": "lemonldap", "cookieName": "lemonldap",
"customFunctions": "My::hello My::get_uri My::get_additional_arg", "customFunctions": "My::hello My::get_additional_arg",
"demoExportedVars": { "demoExportedVars": {
"cn": "cn", "cn": "cn",
"mail": "mail", "mail": "mail",
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
"Auth-User": "$uid", "Auth-User": "$uid",
"Ip-Addr": "$ipAddr", "Ip-Addr": "$ipAddr",
"Hello": "hello()", "Hello": "hello()",
"Uri": "get_uri()", "Uri": "$ENV{REQUEST_URI}",
"Additional-Arg": "get_additional_arg('header-added')", "Additional-Arg": "get_additional_arg('header-added')",
"Base64": "encode_base64('a:b','')" "Base64": "encode_base64('a:b','')"
}, },
......
...@@ -10,10 +10,24 @@ use URI::Escape; ...@@ -10,10 +10,24 @@ use URI::Escape;
sub new { sub new {
my ( $class, $r ) = @_; my ( $class, $r ) = @_;
# Apache populates ENV: # $r->subprocess_env breaks header modification. That's why it is not used
$r->subprocess_env; # here
my $uri = $r->uri;
$uri =~ s#//+#/#g;
$uri =~ s#\?#%3F#g;
my $env = { my $env = {
%ENV,
#%ENV,
HTTP_HOST => $r->hostname,
REMOTE_ADDR => (
$r->connection->can('remote_ip') ? $r->connection->remote_ip
: $r->connection->client_ip
),
QUERY_STRING => $r->args,
REQUEST_URI => $uri . ( $r->args ? '?' . $r->args : '' ),
PATH_INFO => '',
SERVER_PORT => $r->get_server_port,
REQUEST_METHOD => $r->method,
'psgi.version' => [ 1, 1 ], 'psgi.version' => [ 1, 1 ],
'psgi.url_scheme' => ( $ENV{HTTPS} || 'off' ) =~ /^(?:on|1)$/i 'psgi.url_scheme' => ( $ENV{HTTPS} || 'off' ) =~ /^(?:on|1)$/i
? 'https' ? 'https'
...@@ -30,9 +44,15 @@ sub new { ...@@ -30,9 +44,15 @@ sub new {
'psgix.cleanup.handlers' => [], 'psgix.cleanup.handlers' => [],
'psgi.r' => $r, 'psgi.r' => $r,
}; };
if ( defined( my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization} ) ) { $r->headers_in->do(
$env->{HTTP_AUTHORIZATION} = $HTTP_AUTHORIZATION; sub {
} my $h = shift;
my $k = uc($h);
$k =~ s/-/_/g;
$env->{"HTTP_$k"} = $r->headers_in->{$h};
return 1;
}
);
my $uri = URI->new( "http://" . $r->hostname . $r->unparsed_uri ); my $uri = URI->new( "http://" . $r->hostname . $r->unparsed_uri );
$env->{PATH_INFO} = uri_unescape( $uri->path ); $env->{PATH_INFO} = uri_unescape( $uri->path );
...@@ -42,7 +62,7 @@ sub new { ...@@ -42,7 +62,7 @@ sub new {
} }
sub datas { sub datas {
my($self) = @_; my ($self) = @_;
return $self->{datas} ||= {}; return $self->{datas} ||= {};
} }
......
...@@ -25,11 +25,8 @@ sub build_jail { ...@@ -25,11 +25,8 @@ sub build_jail {
return $self->jail return $self->jail
if ( $self->jail if ( $self->jail
and $self->jail->useSafeJail and $self->jail->useSafeJail
and $self->jail->customFunctions
and $self->useSafeJail and $self->useSafeJail
and $self->customFunctions and $self->jail->useSafeJail == $self->useSafeJail );
and $self->jail->useSafeJail == $self->useSafeJail
and $self->jail->customFunctions == $self->customFunctions );
$self->useSafeJail(1) unless defined $self->useSafeJail; $self->useSafeJail(1) unless defined $self->useSafeJail;
...@@ -47,8 +44,7 @@ sub build_jail { ...@@ -47,8 +44,7 @@ sub build_jail {
} }
next if ( $self->can($_) ); next if ( $self->can($_) );
eval "sub $_ { eval "sub $_ {
my \$uri = \$_[1]->{env}->{REQUEST_URI}; return $sub(\@_)
return $sub(\$uri,\@_)
}"; }";
$api->logger->error($@) if ($@); $api->logger->error($@) if ($@);
$_ = "&$_"; $_ = "&$_";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment