| 1 | # Main FastCGI handler adapter for LLNG handler | ||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||
| 3 | # See https://lemonldap-ng.org/documentation/latest/handlerarch | ||||||||||||||||||||||||||||||||||
| 4 | package Lemonldap::NG::Handler::Server::Main; | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 12 | our $VERSION = '2.19.0'; | |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use base 'Lemonldap::NG::Handler::PSGI::Main'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use constant defaultLogger => 'Lemonldap::NG::Common::Logger::Syslog'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | $ENV{LLNG_DEFAULTLOGGER} ||= defaultLogger; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"LLNG_DEFAULTLOGGER"} ||= "Lemonldap::NG::Common::Logger::Syslog"
MC/DC0%0/1
$ENV{"LLNG_DEFAULTLOGGER"} ||= "Lemonldap::NG::Common::Logger::Syslog"
$ENV{"LLNG_DEFAULTLOGGER"}
Truth table50%1/2
A
A= $ENV{"LLNG_DEFAULTLOGGER"}
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | # In server mode, headers are not passed to a PSGI application but returned | ||||||||||||||||||||||||||||||||||
| 17 | # to the server | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | ## @method void setAccessControlUri(hashRef env) | ||||||||||||||||||||||||||||||||||
| 20 | # Set in the environment the URI on which access control must be decided. | ||||||||||||||||||||||||||||||||||
| 21 | # Nginx gives in X_ORIGINAL_URI the URI it routed on ($original_uri, already | ||||||||||||||||||||||||||||||||||
| 22 | # decoded and normalized): it is used as is, decoding it again would give a | ||||||||||||||||||||||||||||||||||
| 23 | # path the application doesn't serve. Without it (Traefik and Caddy, where | ||||||||||||||||||||||||||||||||||
| 24 | # REQUEST_URI is set from X-Forwarded-Uri), REQUEST_URI is the URI as sent by | ||||||||||||||||||||||||||||||||||
| 25 | # the client and is canonicalized (see Handler::Main::canonicalUri()). | ||||||||||||||||||||||||||||||||||
| 26 | # @param $env PSGI environment | ||||||||||||||||||||||||||||||||||
| 27 | 56 | ▶ | sub setAccessControlUri { | ||||||||||||||||||||||||||||||||
|
Subroutine
setAccessControlUri: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 28 | 56 | my ( $class, $env ) = @_; | |||||||||||||||||||||||||||||||||
| 29 | $env->{ACCESS_CONTROL_URI} = $env->{X_ORIGINAL_URI} | ||||||||||||||||||||||||||||||||||
| 30 | 56 | ▶ | || $class->canonicalUri( $env->{REQUEST_URI} ); | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$env->{'X_ORIGINAL_URI'} || $class->canonicalUri($env->{'REQUEST_URI'})
MC/DC0%0/2
$env->{'X_ORIGINAL_URI'} || $class->canonicalUri($env->{'REQUEST_URI'})
$env->{'X_ORIGINAL_URI'}
$class->canonicalUri($env->{'REQUEST_URI'})
Truth table66%2/3
A || B
A= $env->{'X_ORIGINAL_URI'}B= $class->canonicalUri($env->{'REQUEST_URI'})
| |||||||||||||||||||||||||||||||||||
| 31 | 56 | return; | |||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | ## @method void set_header_in(hash headers) | ||||||||||||||||||||||||||||||||||
| 35 | # sets or modifies request headers | ||||||||||||||||||||||||||||||||||
| 36 | # @param headers hash containing header names => header value | ||||||||||||||||||||||||||||||||||
| 37 | 39 | ▶ | sub set_header_in { | ||||||||||||||||||||||||||||||||
|
Subroutine
set_header_in: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 38 | 39 | my ( $class, $req, %headers ) = @_; | |||||||||||||||||||||||||||||||||
| 39 | 39 | for my $k ( keys %headers ) { | |||||||||||||||||||||||||||||||||
| 40 | 72 | $req->{env}->{ cgiName($k) } = $headers{$k}; | |||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||
| 42 | 39 | push @{ $req->{respHeaders} }, %headers; | |||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | ## @method void unset_header_in(array headers) | ||||||||||||||||||||||||||||||||||
| 46 | # deletes request headers and push headers that will be removed by LUA | ||||||||||||||||||||||||||||||||||
| 47 | # @param headers array containing header names | ||||||||||||||||||||||||||||||||||
| 48 | 55 | ▶ | sub unset_header_in { | ||||||||||||||||||||||||||||||||
|
Subroutine
unset_header_in: called CC=7 SCAR=20.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 49 | 55 | my ( $class, $req, @headers ) = @_; | |||||||||||||||||||||||||||||||||
| 50 | 55 | ▶ | $req->data->{deleteIndex} //= 1; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$req->data->{"deleteIndex"} //= 1
MC/DC100%1/1
$req->data->{"deleteIndex"} //= 1
$req->data->{"deleteIndex"}
Truth table100%2/2
A
A= $req->data->{"deleteIndex"}
| |||||||||||||||||||||||||||||||||||
| 51 | 55 | my $i = $req->data->{deleteIndex}; | |||||||||||||||||||||||||||||||||
| 52 | 55 | foreach my $header (@headers) { | |||||||||||||||||||||||||||||||||
| 53 | 55 | $class->logger->debug("Delete header $header"); | |||||||||||||||||||||||||||||||||
| 54 | 55 | my $del = 0; | |||||||||||||||||||||||||||||||||
| 55 | $req->{respHeaders} = [ | ||||||||||||||||||||||||||||||||||
| 56 | map { | ||||||||||||||||||||||||||||||||||
| 57 | 486 | my @res; | |||||||||||||||||||||||||||||||||
| 58 | 486 | ▶ | if ($del) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 59 | 0 | $del = 0; | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | ▶ | elsif ( $_ and ( $_ eq $header or $_ eq cgiName($header) ) ) { | |||||||||||||||||||||||||||||||||
|
Condition50%3/6
$_ and $_ eq $header || $_ eq cgiName($header)
$_ eq $header or $_ eq cgiName($header)
MC/DC0%0/3
$_ and $_ eq $header || $_ eq cgiName($header)
$_
$_ eq $header
$_ eq cgiName($header)
Truth table50%2/4
A and B or C
A= $_B= $_ eq $headerC= $_ eq cgiName($header)
| |||||||||||||||||||||||||||||||||||
| 62 | 0 | $del = 1; | |||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||
| 64 | else { | ||||||||||||||||||||||||||||||||||
| 65 | 486 | @res = ($_); | |||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | 486 | @res; | |||||||||||||||||||||||||||||||||
| 68 | 55 | } @{ $req->{respHeaders} } | |||||||||||||||||||||||||||||||||
| 69 | ]; | ||||||||||||||||||||||||||||||||||
| 70 | 55 | delete $req->{env}->{ cgiName($header) }; | |||||||||||||||||||||||||||||||||
| 71 | 55 | push @{ $req->{respHeaders} }, "Deleteheader$i", $header; | |||||||||||||||||||||||||||||||||
| 72 | 55 | $i++; | |||||||||||||||||||||||||||||||||
| 73 | 55 | push @{ $req->{respHeaders} }, "Deleteheader$i", cgiName($header); | |||||||||||||||||||||||||||||||||
| 74 | 55 | $header =~ s/-/_/g; | |||||||||||||||||||||||||||||||||
| 75 | 55 | delete $req->{env}->{$header}; | |||||||||||||||||||||||||||||||||
| 76 | 55 | $i++; | |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | 55 | $req->data->{deleteIndex} = $i; | |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | # Inheritence is broken in this case with Debian >= jessie | ||||||||||||||||||||||||||||||||||
| 82 | 12 | *checkType = *Lemonldap::NG::Handler::PSGI::Main::checkType; | |||||||||||||||||||||||||||||||||
| 83 | 12 | *setServerSignature = *Lemonldap::NG::Handler::PSGI::Main::setServerSignature; | |||||||||||||||||||||||||||||||||
| 84 | 12 | *thread_share = *Lemonldap::NG::Handler::PSGI::Main::thread_share; | |||||||||||||||||||||||||||||||||
| 85 | 12 | *set_user = *Lemonldap::NG::Handler::PSGI::Main::set_user; | |||||||||||||||||||||||||||||||||
| 86 | 12 | *set_custom = *Lemonldap::NG::Handler::PSGI::Main::set_custom; | |||||||||||||||||||||||||||||||||
| 87 | 12 | *set_header_out = *Lemonldap::NG::Handler::PSGI::Main::set_header_out; | |||||||||||||||||||||||||||||||||
| 88 | 12 | *is_initial_req = *Lemonldap::NG::Handler::PSGI::Main::is_initial_req; | |||||||||||||||||||||||||||||||||
| 89 | 12 | *print = *Lemonldap::NG::Handler::PSGI::Main::print; | |||||||||||||||||||||||||||||||||
| 90 | 12 | *addToHtmlHead = *Lemonldap::NG::Handler::PSGI::Main::addToHtmlHead; | |||||||||||||||||||||||||||||||||
| 91 | 12 | *cgiName = *Lemonldap::NG::Handler::PSGI::Main::cgiName; | |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | 12 | 1; | |||||||||||||||||||||||||||||||||