| 1 | package Plack::Handler::Net::FastCGI; | ||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use IO::Socket qw[]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Net::FastCGI 0.12; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Net::FastCGI::Constant qw[:common :type :flag :role :protocol_status]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Net::FastCGI::IO qw[:all]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Net::FastCGI::Protocol qw[:all]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Plack::TempBuffer qw[]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Plack::Util qw[]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use URI qw[]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use URI::Escape qw[uri_unescape]; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | 1 | eval { | |||||||||||||||||||||||||||||
| 17 | 1 | require PerlIO::code; | |||||||||||||||||||||||||||||
| 18 | }; | ||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | my $mode = $@ ? ">:via(@{[__PACKAGE__]})" : '>:Code'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | *PERLIO_MODE = sub () { $mode }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | sub DEBUG () { 0 } | ||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 26 | 0 | my $class = shift; | |||||||||||||||||||||||||||||
| 27 | 0 | my $self = bless { @_ }, $class; | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $self->{listen} ||= [ ":$self->{port}" ] if $self->{port}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{"listen"} ||= [qq[:$self->{"port"}]]
MC/DC0%0/1
$self->{"listen"} ||= [qq[:$self->{"port"}]]
$self->{"listen"}
Truth table0%0/2
A
A= $self->{"listen"}
| |||||||||||||||||||||||||||||||
| 29 | $self->{values} ||= { | ||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | FCGI_MAX_CONNS => 1, # maximum number of concurrent transport connections this application will accept | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"values"} ||= {"FCGI_MAX_CONNS", 1, "FCGI_MAX_REQS", 1, "FCGI_MPXS_CONNS", 0}
MC/DC0%0/1
$self->{"values"} ||= {"FCGI_MAX_CONNS", 1, "FCGI_MAX_REQS", 1, "FCGI_MPXS_CONNS", 0}
$self->{"values"}
Truth table0%0/2
A
A= $self->{"values"}
| |||||||||||||||||||||||||||||||
| 31 | FCGI_MAX_REQS => 1, # maximum number of concurrent requests this application will accept | ||||||||||||||||||||||||||||||
| 32 | FCGI_MPXS_CONNS => 0, # this implementation can't multiplex | ||||||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||||
| 34 | 0 | $self; | |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||
| 38 | 1 | require Socket; | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | my $HAS_AF_UNIX = eval { Socket->import('AF_UNIX'); defined(my $v = &AF_UNIX) } && !$@; | ||||||||||||||||||||||||||||
|
Condition33%1/3
eval {
do {
'Socket'->import('AF_UNIX');
defined(my $v = &AF_UNIX)
}
} && !$@
MC/DC0%0/2
eval {
do {
'Socket'->import('AF_UNIX');
defined(my $v = &AF_UNIX)
}
} && !$@
eval {
do {
'Socket'->import('AF_UNIX');
defined(my $v = &AF_UNIX)
}
}
!$@
Truth table33%1/3
A && not(B)
A= eval {
do {
'Socket'->import('AF_UNIX');
defined(my $v = &AF_UNIX)
}
}B= !$@
| |||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | *HAS_AF_UNIX = sub () { $HAS_AF_UNIX }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 44 | 0 | my ($self, $app) = @_; | |||||||||||||||||||||||||||||
| 45 | 0 | $self->{app} = $app; | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | 0 | my $socket; | |||||||||||||||||||||||||||||
| 48 | my $proto; | ||||||||||||||||||||||||||||||
| 49 | 0 | my $port; | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($self->{listen}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 52 | 0 | $port = $self->{listen}->[0]; | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($port =~ s/^://) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 54 | 0 | $proto = 'tcp'; | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $socket = IO::Socket::INET->new( | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 56 | Listen => 5, | ||||||||||||||||||||||||||||||
| 57 | LocalPort => $port, | ||||||||||||||||||||||||||||||
| 58 | Reuse => 1 | ||||||||||||||||||||||||||||||
| 59 | ) or die "Couldn't create listener socket: $!"; | ||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||
| 61 | 0 | $proto = 'unix'; | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $socket = IO::Socket::UNIX->new( | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 63 | Listen => 5, | ||||||||||||||||||||||||||||||
| 64 | Local => $port, | ||||||||||||||||||||||||||||||
| 65 | ) or die "Couldn't create UNIX listener socket: $!"; | ||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | (-S STDIN) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 70 | || die "Standard input is not a socket: specify a listen location"; | ||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 0 | $socket = \*STDIN; | |||||||||||||||||||||||||||||
| 73 | 0 | $proto = 'tcp'; | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | 0 | if (HAS_AF_UNIX) { | |||||||||||||||||||||||||||||
| 76 | 0 | my $sockaddr = getsockname(*STDIN); | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if (unpack('S', $sockaddr) == &Socket::AF_UNIX) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 78 | 0 | $proto = 'unix'; | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | $self->{server_ready}->({ | ||||||||||||||||||||||||||||||
| 84 | host => 'localhost', | ||||||||||||||||||||||||||||||
| 85 | port => $port, | ||||||||||||||||||||||||||||||
| 86 | proto => $proto, | ||||||||||||||||||||||||||||||
| 87 | server_software => 'Plack::Handler::Net::FastCGI', | ||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | }) if $self->{server_ready} && $proto; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"server_ready"} and $proto
MC/DC0%0/2
$self->{"server_ready"} and $proto
$self->{"server_ready"}
$proto
Truth table0%0/3
A and B
A= $self->{"server_ready"}B= $proto
| |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | while (accept(my $connection, $socket)) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 91 | 0 | $self->_handle_connection($connection); | |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub _handle_request { | ||||||||||||||||||||||||||||
|
Subroutine
_handle_request: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||
| 96 | 0 | my($self, $env, $stdin, $stdout, $stderr) = @_; | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | $env = { | ||||||||||||||||||||||||||||||
| 99 | %$env, | ||||||||||||||||||||||||||||||
| 100 | 'psgi.version' => [1,1], | ||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | 'psgi.url_scheme' => ($env->{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http', | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$env->{'HTTPS'} || 'off'
MC/DC0%0/1
$env->{'HTTPS'} || 'off'
$env->{'HTTPS'}
Truth table0%0/2
A
A= $env->{'HTTPS'}
| |||||||||||||||||||||||||||||||
| 102 | 'psgi.input' => $stdin, | ||||||||||||||||||||||||||||||
| 103 | 'psgi.errors' => $stderr, | ||||||||||||||||||||||||||||||
| 104 | 'psgi.multithread' => Plack::Util::FALSE, | ||||||||||||||||||||||||||||||
| 105 | 'psgi.multiprocess' => Plack::Util::FALSE, | ||||||||||||||||||||||||||||||
| 106 | 'psgi.run_once' => Plack::Util::FALSE, | ||||||||||||||||||||||||||||||
| 107 | 'psgi.streaming' => Plack::Util::TRUE, | ||||||||||||||||||||||||||||||
| 108 | 'psgi.nonblocking' => Plack::Util::FALSE, | ||||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | 0 | delete $env->{HTTP_CONTENT_TYPE}; | |||||||||||||||||||||||||||||
| 112 | 0 | delete $env->{HTTP_CONTENT_LENGTH}; | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | # lighttpd munges multiple slashes in PATH_INFO into one. Try recovering it | ||||||||||||||||||||||||||||||
| 115 | 0 | my $uri = URI->new("http://localhost" . $env->{REQUEST_URI}); | |||||||||||||||||||||||||||||
| 116 | 0 | $env->{PATH_INFO} = uri_unescape($uri->path); | |||||||||||||||||||||||||||||
| 117 | 0 | $env->{PATH_INFO} =~ s/^\Q$env->{SCRIPT_NAME}\E//; | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | # root access for mod_fastcgi | ||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if (!exists $env->{PATH_INFO}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 121 | 0 | $env->{PATH_INFO} = ''; | |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | 0 | my $res = Plack::Util::run_app $self->{app}, $env; | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if (ref $res eq 'ARRAY') { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 127 | 0 | $self->_handle_response($res, $stdout); | |||||||||||||||||||||||||||||
| 128 | } elsif (ref $res eq 'CODE') { | ||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $res->(sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 130 | 0 | $self->_handle_response($_[0], $stdout); | |||||||||||||||||||||||||||||
| 131 | 0 | }); | |||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||||
| 133 | 0 | die "Bad response $res"; | |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub _handle_response { | ||||||||||||||||||||||||||||
|
Subroutine
_handle_response: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||
| 138 | 0 | my ($self, $res, $stdout) = @_; | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | 0 | my $hdrs; | |||||||||||||||||||||||||||||
| 141 | 0 | $hdrs = "Status: $res->[0]\015\012"; | |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | 0 | my $headers = $res->[1]; | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | while (my ($k, $v) = splice @$headers, 0, 2) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 145 | 0 | $hdrs .= "$k: $v\015\012"; | |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||
| 147 | 0 | $hdrs .= "\015\012"; | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | 0 | print {$stdout} $hdrs; | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | my $cb = sub { print {$stdout} $_[0] }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 152 | 0 | my $body = $res->[2]; | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if (defined $body) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 154 | 0 | Plack::Util::foreach($body, $cb); | |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||
| 156 | else { | ||||||||||||||||||||||||||||||
| 157 | return Plack::Util::inline_object | ||||||||||||||||||||||||||||||
| 158 | write => $cb, | ||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | close => sub { }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | 1 | our $STDOUT_BUFFER_SIZE = 8192; | |||||||||||||||||||||||||||||
| 164 | 1 | our $STDERR_BUFFER_SIZE = 0; | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | use warnings FATAL => 'Net::FastCGI::IO'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub _handle_connection { | ||||||||||||||||||||||||||||
|
Subroutine
_handle_connection: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||
| 169 | 0 | my($self, $socket) = @_; | |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | 0 | my ( $current_id, # id of the request we are currently processing | |||||||||||||||||||||||||||||
| 172 | $stdin, # buffer for stdin | ||||||||||||||||||||||||||||||
| 173 | $stdout, # buffer for stdout | ||||||||||||||||||||||||||||||
| 174 | $stderr, # buffer for stderr | ||||||||||||||||||||||||||||||
| 175 | $params, # buffer for params (environ) | ||||||||||||||||||||||||||||||
| 176 | $done, # done with connection? | ||||||||||||||||||||||||||||||
| 177 | $keep_conn ); # more requests on this connection? | ||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||
| 179 | 0 | ($current_id, $stdin, $stdout, $stderr) = (0, undef, '', ''); | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | while (!$done) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | my ($type, $request_id, $content) = read_record($socket) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 183 | or last; | ||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||
| 185 | 0 | if (DEBUG) { | |||||||||||||||||||||||||||||
| 186 | warn '< ', dump_record($type, $request_id, $content), "\n"; | ||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ($request_id == FCGI_NULL_REQUEST_ID) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if ($type == FCGI_GET_VALUES) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 191 | 0 | my $query = parse_params($content); | |||||||||||||||||||||||||||||
| 192 | 0 | my %reply = map { $_ => $self->{values}->{$_} } | |||||||||||||||||||||||||||||
| 193 | 0 | grep { exists $self->{values}->{$_} } | |||||||||||||||||||||||||||||
| 194 | keys %$query; | ||||||||||||||||||||||||||||||
| 195 | 0 | write_record($socket, FCGI_GET_VALUES_RESULT, | |||||||||||||||||||||||||||||
| 196 | FCGI_NULL_REQUEST_ID, build_params(\%reply)); | ||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||
| 198 | else { | ||||||||||||||||||||||||||||||
| 199 | 0 | write_record($socket, FCGI_UNKNOWN_TYPE, | |||||||||||||||||||||||||||||
| 200 | FCGI_NULL_REQUEST_ID, build_unknown_type($type)); | ||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||
| 203 | ▶ | elsif ($request_id != $current_id && $type != FCGI_BEGIN_REQUEST) { | |||||||||||||||||||||||||||||
|
Condition0%0/3
$request_id != $current_id and $type != 1
MC/DC0%0/2
$request_id != $current_id and $type != 1
$request_id != $current_id
$type != 1
Truth table0%0/3
A and B
A= $request_id != $current_idB= $type != 1
| |||||||||||||||||||||||||||||||
| 204 | # ignore inactive requests (FastCGI Specification 3.3) | ||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||
| 206 | elsif ($type == FCGI_ABORT_REQUEST) { | ||||||||||||||||||||||||||||||
| 207 | 0 | $current_id = 0; | |||||||||||||||||||||||||||||
| 208 | 0 | ($stdin, $stdout, $stderr, $params) = (undef, '', '', ''); | |||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||
| 210 | elsif ($type == FCGI_BEGIN_REQUEST) { | ||||||||||||||||||||||||||||||
| 211 | 0 | my ($role, $flags) = parse_begin_request_body($content); | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ($current_id || $role != FCGI_RESPONDER) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$current_id or $role != 1
MC/DC0%0/2
$current_id or $role != 1
$current_id
$role != 1
Truth table0%0/3
A or B
A= $current_idB= $role != 1
| |||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $status = $current_id ? FCGI_CANT_MPX_CONN : FCGI_UNKNOWN_ROLE; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 214 | 0 | write_record($socket, FCGI_END_REQUEST, $request_id, | |||||||||||||||||||||||||||||
| 215 | build_end_request_body(0, $status)); | ||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||
| 217 | else { | ||||||||||||||||||||||||||||||
| 218 | 0 | $current_id = $request_id; | |||||||||||||||||||||||||||||
| 219 | 0 | $stdin = Plack::TempBuffer->new; | |||||||||||||||||||||||||||||
| 220 | 0 | $keep_conn = ($flags & FCGI_KEEP_CONN); | |||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||
| 223 | elsif ($type == FCGI_PARAMS) { | ||||||||||||||||||||||||||||||
| 224 | 0 | $params .= $content; | |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||
| 226 | elsif ($type == FCGI_STDIN) { | ||||||||||||||||||||||||||||||
| 227 | 0 | $stdin->print($content); | |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | unless (length $content) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 230 | 0 | my $in = $stdin->rewind; | |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my $stdout_cb = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 233 | 0 | $stdout .= $_[0]; | |||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if (length $stdout >= $STDOUT_BUFFER_SIZE) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 235 | 0 | write_stream($socket, FCGI_STDOUT, $current_id, $stdout, 0); | |||||||||||||||||||||||||||||
| 236 | 0 | $stdout = ''; | |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||
| 238 | 0 | }; | |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | open(my $out, PERLIO_MODE, $stdout_cb) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 241 | || die(qq/Couldn't open sub as fh: $!/); | ||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my $stderr_cb = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 244 | 0 | $stderr .= $_[0]; | |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if (length $stderr >= $STDERR_BUFFER_SIZE) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 246 | 0 | write_stream($socket, FCGI_STDERR, $current_id, $stderr, 0); | |||||||||||||||||||||||||||||
| 247 | 0 | $stderr = ''; | |||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||
| 249 | 0 | }; | |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | open(my $err, PERLIO_MODE, $stderr_cb) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 252 | || die(qq/Couldn't open sub as fh: $!/); | ||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||
| 254 | 0 | $self->_handle_request(parse_params($params), $in, $out, $err); | |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||
| 256 | 0 | write_stream($socket, FCGI_STDOUT, $current_id, $stdout, 1); | |||||||||||||||||||||||||||||
| 257 | 0 | write_stream($socket, FCGI_STDERR, $current_id, $stderr, 1); | |||||||||||||||||||||||||||||
| 258 | 0 | write_record($socket, FCGI_END_REQUEST, $current_id, | |||||||||||||||||||||||||||||
| 259 | build_end_request_body(0, FCGI_REQUEST_COMPLETE)); | ||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | # prepare for next request | ||||||||||||||||||||||||||||||
| 262 | 0 | $current_id = 0; | |||||||||||||||||||||||||||||
| 263 | 0 | ($stdin, $stdout, $stderr, $params) = (undef, '', '', ''); | |||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||
| 266 | else { | ||||||||||||||||||||||||||||||
| 267 | 0 | warn(qq/Received an unknown record type '$type'/); | |||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub PUSHED { | ||||||||||||||||||||||||||||
|
Subroutine
PUSHED: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 273 | 0 | my ($class) = @_; | |||||||||||||||||||||||||||||
| 274 | 0 | return bless \(my $self), $class; | |||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | sub OPEN { | ||||||||||||||||||||||||||||
|
Subroutine
OPEN: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 278 | 0 | my ($self, $sub) = @_; | |||||||||||||||||||||||||||||
| 279 | 0 | $$self = $sub; | |||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub WRITE { | ||||||||||||||||||||||||||||
|
Subroutine
WRITE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 283 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||
| 284 | 0 | $$self->($_[1]); | |||||||||||||||||||||||||||||
| 285 | 0 | return length $_[1]; | |||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||
| 288 | 1 | 1; | |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||
| 290 | __END__ | ||||||||||||||||||||||||||||||