diff options
-rw-r--r-- | lib/PublicInbox/GitHTTPBackend.pm | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index 58799707..f8446aa0 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -135,18 +135,7 @@ sub serve_smart { if (fileno($input) >= 0) { $in = $input; } else { # FIXME untested - $in = IO::File->new_tmpfile; - while (1) { - my $r = $input->read($buf, 8192); - unless (defined $r) { - $err->print("error reading input: $!\n"); - return r(500); - } - last if ($r == 0); - $in->write($buf); - } - $in->flush; - $in->sysseek(0, SEEK_SET); + $in = input_to_file($env) or return r(500); } my ($rpipe, $wpipe); unless (pipe($rpipe, $wpipe)) { @@ -249,4 +238,25 @@ sub serve_smart { } } +# FIXME: untested, our -httpd _always_ gives a real file handle +sub input_to_file { + my ($env) = @_; + my $in = IO::File->new_tmpfile; + my $input = $env->{'psgi.input'}; + my $buf; + while (1) { + my $r = $input->read($buf, 8192); + unless (defined $r) { + my $err = $env->{'psgi.errors'}; + $err->print("error reading input: $!\n"); + return; + } + last if ($r == 0); + $in->write($buf); + } + $in->flush; + $in->sysseek(0, SEEK_SET); + return $in; +} + 1; |