Compiler-Parser
view release on metacpan or search on metacpan
t/app/Plack/Handler/FCGI.t view on Meta::CPAN
key => hash_ref { '{}',
data => leaf 'HTTPS',
},
},
right => leaf 'off',
},
right => regexp { '^(?:on|1)$',
option => leaf 'i',
},
},
true_expr => leaf 'https',
false_expr => leaf 'http',
},
},
},
right => branch { '=>',
left => leaf 'psgi.input',
right => branch { '->',
left => leaf '$self',
right => hash_ref { '{}',
data => leaf 'stdin',
},
},
},
},
right => branch { '=>',
left => leaf 'psgi.errors',
right => branch { '->',
left => leaf '$self',
right => hash_ref { '{}',
data => leaf 'stderr',
},
},
},
},
right => branch { '=>',
left => leaf 'psgi.multithread',
right => function_call { 'Plack::Util::FALSE',
args => [
],
},
},
},
right => branch { '=>',
left => leaf 'psgi.multiprocess',
right => function_call { 'Plack::Util::TRUE',
args => [
],
},
},
},
right => branch { '=>',
left => leaf 'psgi.run_once',
right => function_call { 'Plack::Util::FALSE',
args => [
],
},
},
},
right => branch { '=>',
left => leaf 'psgi.streaming',
right => function_call { 'Plack::Util::TRUE',
args => [
],
},
},
},
right => branch { '=>',
left => leaf 'psgi.nonblocking',
right => function_call { 'Plack::Util::FALSE',
args => [
],
},
},
},
right => branch { '=>',
left => leaf 'psgix.harakiri',
right => function_call { 'defined',
args => [
leaf '$proc_manager',
],
},
},
},
},
},
},
function_call { 'delete',
args => [
branch { '->',
left => leaf '$env',
right => hash_ref { '{}',
data => leaf 'HTTP_CONTENT_TYPE',
},
},
],
},
function_call { 'delete',
args => [
branch { '->',
left => leaf '$env',
right => hash_ref { '{}',
data => leaf 'HTTP_CONTENT_LENGTH',
},
},
],
},
branch { '=',
left => leaf '$uri',
right => branch { '->',
left => leaf 'URI',
right => function_call { 'new',
args => [
branch { '.',
left => leaf 'http://localhost',
right => branch { '->',
left => leaf '$env',
right => hash_ref { '{}',
data => leaf 'REQUEST_URI',
},
},
t/app/Plack/Handler/FCGI.t view on Meta::CPAN
}
} elsif (!RUNNING_IN_HELL) {
die "STDIN is not a socket: specify a listen location";
}
@{$self}{qw(stdin stdout stderr)}
= (IO::Handle->new, IO::Handle->new, IO::Handle->new);
my %env;
my $request = FCGI::Request(
$self->{stdin}, $self->{stdout},
($self->{keep_stderr} ? $self->{stdout} : $self->{stderr}), \%env, $sock,
($self->{nointr} ? 0 : &FCGI::FAIL_ACCEPT_ON_INTR),
);
my $proc_manager;
if ($self->{listen}) {
$self->daemon_fork if $self->{daemonize};
if ($self->{manager}) {
if (blessed $self->{manager}) {
for (qw(nproc pid proc_title)) {
die "Don't use '$_' when passing in a 'manager' object"
if $self->{$_};
}
$proc_manager = $self->{manager};
} else {
Plack::Util::load_class($self->{manager});
$proc_manager = $self->{manager}->new({
n_processes => $self->{nproc},
pid_fname => $self->{pid},
(exists $self->{proc_title}
? (pm_title => $self->{proc_title}) : ()),
});
}
# detach *before* the ProcManager inits
$self->daemon_detach if $self->{daemonize};
$proc_manager->pm_manage;
}
elsif ($self->{daemonize}) {
$self->daemon_detach;
}
}
while ($request->Accept >= 0) {
$proc_manager && $proc_manager->pm_pre_dispatch;
my $env = {
%env,
'psgi.version' => [1,1],
'psgi.url_scheme' => ($env{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
'psgi.input' => $self->{stdin},
'psgi.errors' => $self->{stderr}, # FCGI.pm redirects STDERR in Accept() loop, so just print STDERR
# print to the correct error handle based on keep_stderr
'psgi.multithread' => Plack::Util::FALSE,
'psgi.multiprocess' => Plack::Util::TRUE,
'psgi.run_once' => Plack::Util::FALSE,
'psgi.streaming' => Plack::Util::TRUE,
'psgi.nonblocking' => Plack::Util::FALSE,
'psgix.harakiri' => defined $proc_manager,
};
delete $env->{HTTP_CONTENT_TYPE};
delete $env->{HTTP_CONTENT_LENGTH};
# lighttpd munges multiple slashes in PATH_INFO into one. Try recovering it
my $uri = URI->new("http://localhost" . $env->{REQUEST_URI});
$env->{PATH_INFO} = uri_unescape($uri->path);
$env->{PATH_INFO} =~ s/^\Q$env->{SCRIPT_NAME}\E//;
# root access for mod_fastcgi
if (!exists $env->{PATH_INFO}) {
$env->{PATH_INFO} = '';
}
# typical fastcgi_param from nginx might get empty values
for my $key (qw(CONTENT_TYPE CONTENT_LENGTH)) {
no warnings;
delete $env->{$key} if exists $env->{$key} && $env->{$key} eq '';
}
if (defined(my $HTTP_AUTHORIZATION = $env->{Authorization})) {
$env->{HTTP_AUTHORIZATION} = $HTTP_AUTHORIZATION;
}
my $res = Plack::Util::run_app $app, $env;
if (ref $res eq 'ARRAY') {
$self->_handle_response($res);
}
elsif (ref $res eq 'CODE') {
$res->(sub {
$self->_handle_response($_[0]);
});
}
else {
die "Bad response $res";
}
# give pm_post_dispatch the chance to do things after the client thinks
# the request is done
$request->Finish;
$proc_manager && $proc_manager->pm_post_dispatch();
if ($proc_manager && $env->{'psgix.harakiri.commit'}) {
$proc_manager->pm_exit("safe exit with harakiri");
}
}
}
sub _handle_response {
my ($self, $res) = @_;
$self->{stdout}->autoflush(1);
binmode $self->{stdout};
my $hdrs;
( run in 0.572 second using v1.01-cache-2.11-cpan-39bf76dae61 )