Workarround a bug which duplicates headers in Traefik handler

This commit is contained in:
Daniel Berteaud 2023-11-20 09:26:08 +01:00
parent 6fc059ea2d
commit 6fb1db0412
3 changed files with 58 additions and 3 deletions

47
templates/Traefik.pm Normal file
View File

@ -0,0 +1,47 @@
package Lemonldap::NG::Handler::Server::Traefik;
use strict;
use Mouse;
use Lemonldap::NG::Handler::Server::Main;
our $VERSION = '2.17.0';
extends 'Lemonldap::NG::Handler::PSGI';
sub init {
my $self = shift;
$self->api('Lemonldap::NG::Handler::Server::Main');
my $tmp = $self->SUPER::init(@_);
}
sub _run {
my $self = shift;
# Create regular _authAndTrace PSGI app
my $app = $self->psgiAdapter(
sub {
my $req = $_[0];
return $self->_authAndTrace($req);
}
);
# Middleware to set correct values for Traefik
return sub {
my $env = $_[0];
$env->{HTTP_HOST} = $env->{HTTP_X_FORWARDED_HOST};
$env->{REQUEST_URI} = $env->{HTTP_X_FORWARDED_URI};
return $app->($env);
}
}
sub handler {
my ( $self, $req ) = @_;
my @convertedHdrs =
( 'Content-Length' => 0, Cookie => ( $req->env->{HTTP_COOKIE} // '' ) );
while ( my ( $k, $v ) = splice( @{ $req->{respHeaders} }, 0, 2 ) ) {
push @convertedHdrs, $k, $v;
}
return [ 200, \@convertedHdrs, [] ];
}
1;

View File

@ -1,5 +1,5 @@
[all]
logLevel = notice
logLevel = debug
logger = Lemonldap::NG::Common::Logger::Std
userLogger = Lemonldap::NG::Common::Logger::Std
localSessionStorage = Cache::FileCache

View File

@ -153,6 +153,7 @@ _EOF
image = [[ .lemonldap.image | toJSON ]]
volumes = [
"secrets/lemonldap-ng.ini:/etc/lemonldap-ng/lemonldap-ng.ini:ro",
"local/Traefik.pm:/usr/share/perl5/vendor_perl/Lemonldap/NG/Handler/Server/Traefik.pm:ro"
]
}
@ -168,15 +169,22 @@ _EOF
}
template {
data =<<_EOF
data =<<_EOT
[[ template "traefik/lemonldap-ng.ini.tpl" . ]]
_EOF
_EOT
destination = "secrets/lemonldap-ng.ini"
perms = "0400"
uid = 100048
gid = 100048
}
template {
data = <<_EOT
[[ template "traefik/Traefik.pm" ]]
_EOT
destination = "local/Traefik.pm"
}
[[ template "common/resources.tpl" .lemonldap.resources ]]
}
[[- end ]]