« blib/lib/Lemonldap/NG/Common/MessageBroker/Redis.pm
↑ Summary
blib/lib/Lemonldap/NG/Common/Conf/Backends/DBI.pm »
| 1 | package Lemonldap::NG::Common::PSGI::Request; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Plack::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | our $VERSION = '2.19.0'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | our @ISA = ('Plack::Request'); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # http :// server / path ? query # fragment | ||||||||||||||||||||||||||||
| 14 | # m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|; | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ( $self, $env ) = @_; | |||||||||||||||||||||||||||
| 18 | 0 | foreach ( keys %$env ) { | |||||||||||||||||||||||||||
| 19 | 0 | ▶ | $self->{$_} ||= $env->{$_} if (/^(?:HTTP|SSL)_/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{$_} ||= $env->{$_}
MC/DC0%0/2
$self->{$_} ||= $env->{$_}
$self->{$_}
$env->{$_}
Truth table0%0/3
A ||= B
A= $self->{$_}B= $env->{$_}
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 13 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 13 | my $self = Plack::Request::new(@_); | |||||||||||||||||||||||||||
| 25 | $self->env->{REQUEST_URI} = $self->env->{X_ORIGINAL_URI} | ||||||||||||||||||||||||||||
| 26 | 13 | ▶ | if ( $self->env->{X_ORIGINAL_URI} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 13 | $self->env->{PATH_INFO} =~ s|//+|/|g; | |||||||||||||||||||||||||||
| 28 | 13 | ▶ | $self->env->{PATH_INFO} ||= '/'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->env->{"PATH_INFO"} ||= "/"
MC/DC100%1/1
$self->env->{"PATH_INFO"} ||= "/"
$self->env->{"PATH_INFO"}
Truth table100%2/2
A
A= $self->env->{"PATH_INFO"}
| |||||||||||||||||||||||||||||
| 29 | 13 | $self->env->{REQUEST_URI} =~ s|^//+|/|g; | |||||||||||||||||||||||||||
| 30 | 13 | $self->{uri} = uri_unescape( $self->env->{REQUEST_URI} ); | |||||||||||||||||||||||||||
| 31 | 13 | $self->{data} = {}; | |||||||||||||||||||||||||||
| 32 | $self->{request_id} = ( $self->env->{UNIQUE_ID} | ||||||||||||||||||||||||||||
| 33 | 13 | ▶ | || join( '', map { [ 0 .. 9, "a" .. "f" ]->[ rand 16 ] } 1 .. 16 ) ); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->env->{'UNIQUE_ID'} || join('', map({[0..9, ('a', 'b', 'c', 'd', 'e', 'f')]->[rand 16];} 1..16))
MC/DC0%0/2
$self->env->{'UNIQUE_ID'} || join('', map({[0..9, ('a', 'b', 'c', 'd', 'e', 'f')]->[rand 16];} 1..16))
$self->env->{'UNIQUE_ID'}
join('', map({[0..9, ('a', 'b', 'c', 'd', 'e', 'f')]->[rand 16];} 1..16))
Truth table66%2/3
A || B
A= $self->env->{'UNIQUE_ID'}B= join('', map({[0..9, ('a', 'b', 'c', 'd', 'e', 'f')]->[rand 16];} 1..16))
| |||||||||||||||||||||||||||||
| 34 | 13 | $self->{error} = 0; | |||||||||||||||||||||||||||
| 35 | 13 | $self->{respHeaders} = []; | |||||||||||||||||||||||||||
| 36 | 13 | return bless( $self, $_[0] ); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub data { return $_[0]->{data} } | ||||||||||||||||||||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub uri { return $_[0]->{uri} } | ||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # URI tested by locationRules. It must be the path the request is really | ||||||||||||||||||||||||||||
| 44 | # served at, else rules can be bypassed with an encoded URL: | ||||||||||||||||||||||||||||
| 45 | # - handlers protecting another application (Nginx, Traefik, mod_perl) set it | ||||||||||||||||||||||||||||
| 46 | # in ACCESS_CONTROL_URI, see Handler::Server::Main::setAccessControlUri() | ||||||||||||||||||||||||||||
| 47 | # and Handler::ApacheMP2::Request | ||||||||||||||||||||||||||||
| 48 | # - otherwise (portal, manager, api), it is PATH_INFO, the path the LLNG | ||||||||||||||||||||||||||||
| 49 | # router uses, followed by the query string as received | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub access_control_uri { | ||||||||||||||||||||||||||
|
Subroutine
access_control_uri: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 52 | 0 | my $env = $self->env; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | return $env->{ACCESS_CONTROL_URI} if defined $env->{ACCESS_CONTROL_URI}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | my $qs = $env->{QUERY_STRING}; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | return $env->{PATH_INFO} . ( defined $qs && length $qs ? "?$qs" : '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $qs and length $qs
MC/DC0%0/2
defined $qs and length $qs
defined $qs
length $qs
Truth table0%0/3
A and B
A= defined $qsB= length $qs
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 13 | ▶ | sub request_id { return $_[0]->{request_id} } | ||||||||||||||||||||||||||
|
Subroutine
request_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub userData { | ||||||||||||||||||||||||||
|
Subroutine
userData: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | my ( $self, $v ) = @_; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | return $self->{userData} = $v if ($v); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | return $self->{userData} | ||||||||||||||||||||||||||||
| 64 | || { | ||||||||||||||||||||||||||||
| 65 | ( $Lemonldap::NG::Handler::Main::tsv->{whatToTrace} | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | || '_whatToTrace' ) => $self->{user}, }; | ||||||||||||||||||||||||||
|
Condition0%0/4
$self->{'userData'} || {$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'} || '_whatToTrace', $self->{'user'}}
$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'} || '_whatToTrace'
MC/DC0%0/1
$self->{'userData'} || {$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'} || '_whatToTrace', $self->{'user'}}
$self->{'userData'}
MC/DC0%0/1
$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'} || '_whatToTrace'
$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'}
Truth table0%0/2
A
A= $self->{'userData'}
Truth table0%0/2
A
A= $Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'}
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub respHeaders { | ||||||||||||||||||||||||||
|
Subroutine
respHeaders: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my ( $self, $respHeaders ) = @_; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | $self->{respHeaders} = $respHeaders if ($respHeaders); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | return $self->{respHeaders}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub spliceHdrs { | ||||||||||||||||||||||||||
|
Subroutine
spliceHdrs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 77 | 0 | return splice @{ $self->{respHeaders} }; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub accept { $_[0]->env->{HTTP_ACCEPT} } | ||||||||||||||||||||||||||
|
Subroutine
accept: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub encodings { $_[0]->env->{HTTP_ACCEPT_ENCODING} } | ||||||||||||||||||||||||||
|
Subroutine
encodings: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub languages { $_[0]->env->{HTTP_ACCEPT_LANGUAGE} } | ||||||||||||||||||||||||||
|
Subroutine
languages: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub authorization { $_[0]->env->{HTTP_AUTHORIZATION} } | ||||||||||||||||||||||||||
|
Subroutine
authorization: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub hostname { $_[0]->env->{HTTP_HOST} } | ||||||||||||||||||||||||||
|
Subroutine
hostname: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub origin { $_[0]->env->{HTTP_ORIGIN} } | ||||||||||||||||||||||||||
|
Subroutine
origin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub referer { $_[0]->env->{REFERER} } | ||||||||||||||||||||||||||
|
Subroutine
referer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub query_string { $_[0]->env->{QUERY_STRING} } | ||||||||||||||||||||||||||
|
Subroutine
query_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 0 | my ( $self, $err ) = @_; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | $self->{error} = $err if ($err); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | return $self->{error}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 8 | *params = \&Plack::Request::param; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub set_param { | ||||||||||||||||||||||||||
|
Subroutine
set_param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 0 | my ( $self, $k, $v ) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | $self->param; | |||||||||||||||||||||||||||
| 100 | $self->env->{'plack.request.merged'}->{$k} = | ||||||||||||||||||||||||||||
| 101 | 0 | $self->env->{'plack.request.query'}->{$k} = $v; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub wantJSON { | ||||||||||||||||||||||||||
|
Subroutine
wantJSON: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_[0]->accept and $_[0]->accept =~ m[(?:application|text)/json]
MC/DC0%0/2
defined $_[0]->accept and $_[0]->accept =~ m[(?:application|text)/json]
defined $_[0]->accept
$_[0]->accept =~ m[(?:application|text)/json]
Truth table0%0/3
A and B
A= defined $_[0]->acceptB= $_[0]->accept =~ m[(?:application|text)/json]
| |||||||||||||||||||||||||||||
| 106 | if ( defined $_[0]->accept | ||||||||||||||||||||||||||||
| 107 | and $_[0]->accept =~ m#(?:application|text)/json# ); | ||||||||||||||||||||||||||||
| 108 | 0 | return 0; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # JSON parser | ||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub jsonBodyToObj { | ||||||||||||||||||||||||||
|
Subroutine
jsonBodyToObj: called CC=5 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 114 | 1 | ▶ | return $self->{json_body} if ( $self->{json_body} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 1 | ▶ | unless ( $self->content_type =~ /application\/json/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $self->error('Data is not JSON'); | |||||||||||||||||||||||||||
| 117 | 0 | return undef; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 1 | ▶ | unless ( $self->body ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $self->error('No data'); | |||||||||||||||||||||||||||
| 121 | 0 | return undef; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 1 | my $j = eval { from_json( $self->content, { allow_nonref => 1 } ) }; | |||||||||||||||||||||||||||
| 124 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | $self->error("$@$!"); | |||||||||||||||||||||||||||
| 126 | 0 | return undef; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 1 | return $self->{json_body} = $j; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 8 | 1; | |||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||