Skip to content

Commit

Permalink
Provide I/O handles to FCGI::Request() instead of relying on global S…
Browse files Browse the repository at this point in the history
…TD{IN,OUT, ERR}, this to prevent clashes with IPC software such as Capture::Tiny.
  • Loading branch information
chansen committed Mar 7, 2012
1 parent 4090965 commit cafa5db
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/Plack/Handler/FCGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ sub run {
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(
\*STDIN, \*STDOUT,
($self->{keep_stderr} ? \*STDOUT : \*STDERR), \%env, $sock,
$self->{stdin}, $self->{stdout},
($self->{keep_stderr} ? $self->{stdout} : $self->{stderr}), \%env, $sock,
($self->{nointr} ? 0 : &FCGI::FAIL_ACCEPT_ON_INTR),
);

Expand Down Expand Up @@ -93,9 +96,9 @@ sub run {
%env,
'psgi.version' => [1,1],
'psgi.url_scheme' => ($env{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
'psgi.input' => *STDIN,
'psgi.errors' => *STDERR, # FCGI.pm redirects STDERR in Accept() loop, so just print STDERR
# print to the correct error handle based on keep_stderr
'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,
Expand Down Expand Up @@ -171,9 +174,9 @@ sub _handle_response {
}
$hdrs .= "\015\012";

print STDOUT $hdrs;
print { $self->{stdout} } $hdrs;

my $cb = sub { print STDOUT $_[0] };
my $cb = sub { print { $self->{stdout} } $_[0] };
my $body = $res->[2];
if (defined $body) {
Plack::Util::foreach($body, $cb);
Expand Down

0 comments on commit cafa5db

Please sign in to comment.