From 93c83c090d377dfebe793c25b47e1ac29f80453e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 26 Feb 2016 01:57:54 +0000 Subject: git-http-backend: extract input_to_file function This will allow us to more easily read and test later. --- lib/PublicInbox/GitHTTPBackend.pm | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'lib/PublicInbox/GitHTTPBackend.pm') 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; -- cgit v1.2.3-24-ge0c7