| 1 | package YATT::Lite::PSGIEnv; sub Env () {__PACKAGE__} | ||||||||||||||||||||||||||||
| 2 | 76 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 76 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 76 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 76 | my @PSGI_FIELDS; | |||||||||||||||||||||||||||
| 7 | 76 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | @PSGI_FIELDS | ||||||||||||||||||||||||||||
| 9 | 76 | = qw/ | |||||||||||||||||||||||||||
| 10 | HTTPS | ||||||||||||||||||||||||||||
| 11 | GATEWAY_INTERFACE | ||||||||||||||||||||||||||||
| 12 | REQUEST_METHOD | ||||||||||||||||||||||||||||
| 13 | SCRIPT_NAME | ||||||||||||||||||||||||||||
| 14 | SCRIPT_FILENAME | ||||||||||||||||||||||||||||
| 15 | DOCUMENT_ROOT | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | PATH_INFO | ||||||||||||||||||||||||||||
| 18 | PATH_TRANSLATED | ||||||||||||||||||||||||||||
| 19 | REDIRECT_STATUS | ||||||||||||||||||||||||||||
| 20 | REDIRECT_HANDLER | ||||||||||||||||||||||||||||
| 21 | REDIRECT_URL | ||||||||||||||||||||||||||||
| 22 | REQUEST_URI | ||||||||||||||||||||||||||||
| 23 | DOCUMENT_URI | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | QUERY_STRING | ||||||||||||||||||||||||||||
| 26 | CONTENT_TYPE | ||||||||||||||||||||||||||||
| 27 | CONTENT_LENGTH | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | SERVER_NAME | ||||||||||||||||||||||||||||
| 30 | SERVER_PORT | ||||||||||||||||||||||||||||
| 31 | SERVER_PROTOCOL | ||||||||||||||||||||||||||||
| 32 | HTTP_USER_AGENT | ||||||||||||||||||||||||||||
| 33 | HTTP_REFERER | ||||||||||||||||||||||||||||
| 34 | HTTP_COOKIE | ||||||||||||||||||||||||||||
| 35 | HTTP_FORWARDED | ||||||||||||||||||||||||||||
| 36 | HTTP_HOST | ||||||||||||||||||||||||||||
| 37 | HTTP_PROXY_CONNECTION | ||||||||||||||||||||||||||||
| 38 | HTTP_ACCEPT | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | HTTP_ACCEPT_CHARSET | ||||||||||||||||||||||||||||
| 41 | HTTP_ACCEPT_LANGUAGE | ||||||||||||||||||||||||||||
| 42 | HTTP_ACCEPT_ENCODING | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | REMOTE_ADDR | ||||||||||||||||||||||||||||
| 45 | REMOTE_HOST | ||||||||||||||||||||||||||||
| 46 | REMOTE_USER | ||||||||||||||||||||||||||||
| 47 | HTTP_X_REAL_IP | ||||||||||||||||||||||||||||
| 48 | HTTP_X_CLIENT_IP | ||||||||||||||||||||||||||||
| 49 | HTTP_X_FORWARDED_FOR | ||||||||||||||||||||||||||||
| 50 | HTTP_X_FORWARDED_PROTO | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | psgi.version | ||||||||||||||||||||||||||||
| 53 | psgi.url_scheme | ||||||||||||||||||||||||||||
| 54 | psgi.input | ||||||||||||||||||||||||||||
| 55 | psgi.errors | ||||||||||||||||||||||||||||
| 56 | psgi.multithread | ||||||||||||||||||||||||||||
| 57 | psgi.multiprocess | ||||||||||||||||||||||||||||
| 58 | psgi.run_once | ||||||||||||||||||||||||||||
| 59 | psgi.nonblocking | ||||||||||||||||||||||||||||
| 60 | psgi.streaming | ||||||||||||||||||||||||||||
| 61 | plack.session | ||||||||||||||||||||||||||||
| 62 | psgix.session | ||||||||||||||||||||||||||||
| 63 | psgix.session.options | ||||||||||||||||||||||||||||
| 64 | psgix.logger | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | yatt.script_name | ||||||||||||||||||||||||||||
| 67 | yatt.script_dir | ||||||||||||||||||||||||||||
| 68 | /; | ||||||||||||||||||||||||||||
| 69 | 76 | our %FIELDS = map {$_ => ''} @PSGI_FIELDS; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 76 | ▶ | use YATT::Lite::Util qw(ckeval globref define_const); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 371 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=9 SCAR=27.0
| |||||||||||||||||||||||||||||
| 75 | 371 | my ($myPack, @more_fields) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 371 | my $callpack = caller; | |||||||||||||||||||||||||||
| 78 | 371 | my $envpack = $callpack . "::Env"; | |||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 371 | my $sym = globref($callpack, 'Env'); | |||||||||||||||||||||||||||
| 81 | 371 | ▶ | if (my $val = *{$sym}{CODE}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | my $old = $val->(); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | croak "Conflicting definition of Env" unless $old eq $envpack; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||
| 85 | 371 | define_const($sym, $envpack); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 371 | my $sym = globref($envpack, 'ISA'); | |||||||||||||||||||||||||||
| 90 | 371 | my $val; | |||||||||||||||||||||||||||
| 91 | 371 | ▶ | if ($val = *{$sym}{ARRAY} and @$val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$val = *{$sym;}{"ARRAY"} and @$val
MC/DC0%0/2
$val = *{$sym;}{"ARRAY"} and @$val
$val = *{$sym;}{"ARRAY"}
@$val
Truth table33%1/3
A and B
A= $val = *{$sym;}{"ARRAY"}B= @$val
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | croak "Conflicting definition of ISA: @$val" unless grep {$_ eq $myPack} @$val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||
| 94 | 371 | *$sym = [$myPack]; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||
| 98 | 371 | my $sym = globref($envpack, 'FIELDS'); | |||||||||||||||||||||||||||
| 99 | 371 | my $fields = +{map {$_ => 1} @PSGI_FIELDS, @more_fields}; | |||||||||||||||||||||||||||
| 100 | 371 | ▶ | if (my $val = *{$sym}{HASH}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | foreach my $f (keys %$fields) { | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | unless ($val->{$f} == $fields->{$f}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | croak "Conflicting definition of field $f"; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||
| 107 | 371 | *$sym = $fields; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub psgi_fields { | ||||||||||||||||||||||||||
|
Subroutine
psgi_fields: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | wantarray ? @PSGI_FIELDS : {map {$_ => 1} @PSGI_FIELDS}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||
| 117 | # Env->is_https($env): true if the request reached us over TLS, by any of | ||||||||||||||||||||||||||||
| 118 | # psgi.url_scheme, X-Forwarded-Proto (set by a TLS-terminating proxy, | ||||||||||||||||||||||||||||
| 119 | # same as mkprefix trusts it) or the CGI-style HTTPS variable. | ||||||||||||||||||||||||||||
| 120 | # Used to decide the Secure attribute of session cookies, so any | ||||||||||||||||||||||||||||
| 121 | # positive signal counts. | ||||||||||||||||||||||||||||
| 122 | # | ||||||||||||||||||||||||||||
| 123 | 35 | ▶ | sub is_https { | ||||||||||||||||||||||||||
|
Subroutine
is_https: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 35 | my ($pack, $env) = @_; | |||||||||||||||||||||||||||
| 125 | 35 | ▶ | return 0 unless $env; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 35 | foreach my $scheme ($env->{'psgi.url_scheme'}, $env->{HTTP_X_FORWARDED_PROTO}) { | |||||||||||||||||||||||||||
| 127 | 68 | ▶ | return 1 if defined $scheme and lc($scheme) eq 'https'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $scheme and lc $scheme eq "https"
MC/DC100%2/2
defined $scheme and lc $scheme eq "https"
defined $scheme
lc $scheme eq "https"
Truth table100%3/3
A and B
A= defined $schemeB= lc $scheme eq "https"
| |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 31 | ▶ | if (defined(my $https = $env->{HTTPS})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 3 | ▶ | return 1 if length $https and lc($https) ne 'off'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $https and lc $https ne "off"
MC/DC50%1/2
length $https and lc $https ne "off"
length $https
lc $https ne "off"
Truth table66%2/3
A and B
A= length $httpsB= lc $https ne "off"
| |||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 29 | 0; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 185 | ▶ | sub psgi_simple_env { | ||||||||||||||||||||||||||
|
Subroutine
psgi_simple_env: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 185 | my ($pack) = shift; | |||||||||||||||||||||||||||
| 137 | 185 | my Env $given = {@_}; | |||||||||||||||||||||||||||
| 138 | 185 | my Env $env = {}; | |||||||||||||||||||||||||||
| 139 | 185 | $env->{'psgi.version'} = [1, 1]; | |||||||||||||||||||||||||||
| 140 | 185 | $env->{'psgi.url_scheme'} = 'http'; | |||||||||||||||||||||||||||
| 141 | 185 | $env->{'psgi.input'} = \*STDIN; | |||||||||||||||||||||||||||
| 142 | 185 | $env->{'psgi.errors'} = \*STDERR; | |||||||||||||||||||||||||||
| 143 | 185 | $env->{'psgi.multithread'} = 0; | |||||||||||||||||||||||||||
| 144 | 185 | $env->{'psgi.multiprocess'} = 0; | |||||||||||||||||||||||||||
| 145 | 185 | $env->{'psgi.run_once'} = 0; | |||||||||||||||||||||||||||
| 146 | 185 | $env->{'psgi.nonblocking'} = 0; | |||||||||||||||||||||||||||
| 147 | 185 | $env->{'psgi.streaming'} = 0; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 185 | ▶ | $env->{PATH_INFO} = $given->{PATH_INFO} || '/'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$given->{'PATH_INFO'} || '/'
MC/DC100%1/1
$given->{'PATH_INFO'} || '/'
$given->{'PATH_INFO'}
Truth table100%2/2
A
A= $given->{'PATH_INFO'}
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 185 | $env; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 76 | 1; | |||||||||||||||||||||||||||