about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-02-26 01:57:54 +0000
committerEric Wong <e@80x24.org>2016-02-26 02:37:06 +0000
commit93c83c090d377dfebe793c25b47e1ac29f80453e (patch)
treeba156a61228398981d6ebac00787c2d91016dbcf /lib
parent85ffb85da388fdc25c0d2f9d7faf3172efed110b (diff)
downloadpublic-inbox-93c83c090d377dfebe793c25b47e1ac29f80453e.tar.gz
This will allow us to more easily read and test later.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/GitHTTPBackend.pm34
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;