Commit ed823b9e authored by Xavier Guimard's avatar Xavier Guimard

Restore headers with Apache (#1044)

parent 75ffa010
......@@ -4,12 +4,8 @@ sub hello {
return 'Hello';
}
sub get_uri {
return $_[0];
}
sub get_additional_arg {
return $_[1];
return $_[0];
}
1;
......@@ -91,7 +91,7 @@
"cfgNum": "1",
"cfgVersion": "2.0.0",
"cookieName": "lemonldap",
"customFunctions": "My::hello My::get_uri My::get_additional_arg",
"customFunctions": "My::hello My::get_additional_arg",
"demoExportedVars": {
"cn": "cn",
"mail": "mail",
......@@ -103,7 +103,7 @@
"Auth-User": "$uid",
"Ip-Addr": "$ipAddr",
"Hello": "hello()",
"Uri": "get_uri()",
"Uri": "$ENV{REQUEST_URI}",
"Additional-Arg": "get_additional_arg('header-added')",
"Base64": "encode_base64('a:b','')"
},
......
......@@ -10,10 +10,24 @@ use URI::Escape;
sub new {
my ( $class, $r ) = @_;
# Apache populates ENV:
$r->subprocess_env;
# $r->subprocess_env breaks header modification. That's why it is not used
# here
my $uri = $r->uri;
$uri =~ s#//+#/#g;
$uri =~ s#\?#%3F#g;
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.url_scheme' => ( $ENV{HTTPS} || 'off' ) =~ /^(?:on|1)$/i
? 'https'
......@@ -30,9 +44,15 @@ sub new {
'psgix.cleanup.handlers' => [],
'psgi.r' => $r,
};
if ( defined( my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization} ) ) {
$env->{HTTP_AUTHORIZATION} = $HTTP_AUTHORIZATION;
}
$r->headers_in->do(
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 );
$env->{PATH_INFO} = uri_unescape( $uri->path );
......@@ -42,7 +62,7 @@ sub new {
}
sub datas {
my($self) = @_;
my ($self) = @_;
return $self->{datas} ||= {};
}
......
......@@ -25,11 +25,8 @@ sub build_jail {
return $self->jail
if ( $self->jail
and $self->jail->useSafeJail
and $self->jail->customFunctions
and $self->useSafeJail
and $self->customFunctions
and $self->jail->useSafeJail == $self->useSafeJail
and $self->jail->customFunctions == $self->customFunctions );
and $self->jail->useSafeJail == $self->useSafeJail );
$self->useSafeJail(1) unless defined $self->useSafeJail;
......@@ -47,8 +44,7 @@ sub build_jail {
}
next if ( $self->can($_) );
eval "sub $_ {
my \$uri = \$_[1]->{env}->{REQUEST_URI};
return $sub(\$uri,\@_)
return $sub(\@_)
}";
$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