From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B905520379 for ; Tue, 12 Mar 2019 04:00:46 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/13] githttpbackend: move more psgi.input handling into subroutine Date: Tue, 12 Mar 2019 04:00:39 +0000 Message-Id: <20190312040046.4619-7-e@80x24.org> In-Reply-To: <20190312040046.4619-1-e@80x24.org> References: <20190312040046.4619-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This will be useful for other CGI wrappers we make. This also fixes a bug with some PSGI servers which did not present a real IO::Handle in the psgi.input env field. --- lib/PublicInbox/GitHTTPBackend.pm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index ab43a00..be5b924 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -182,11 +182,6 @@ sub prepare_range { # returns undef if 403 so it falls back to dumb HTTP sub serve_smart { my ($env, $git, $path) = @_; - my $in = $env->{'psgi.input'}; - my $fd = eval { fileno($in) }; - unless (defined $fd && $fd >= 0) { - $in = input_to_file($env) or return r(500); - } my %env = %ENV; # GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL # may be set in the server-process and are passed as-is @@ -202,7 +197,7 @@ sub serve_smart { my $limiter = $git->{-httpbackend_limiter} || $default_limiter; $env{GIT_HTTP_EXPORT_ALL} = '1'; $env{PATH_TRANSLATED} = "$git->{git_dir}/$path"; - my $rdr = { 0 => fileno($in) }; + my $rdr = input_prepare($env) or return r(500); my $qsp = PublicInbox::Qspawn->new([qw(git http-backend)], \%env, $rdr); $qsp->psgi_return($env, $limiter, sub { my ($r, $bref) = @_; @@ -211,14 +206,19 @@ sub serve_smart { }); } -sub input_to_file { +sub input_prepare { my ($env) = @_; + + my $input = $env->{'psgi.input'}; + my $fd = eval { fileno($input) }; + if (defined $fd && $fd >= 0) { + return { 0 => $fd }; + } open(my $in, '+>', undef); unless (defined $in) { err($env, "could not open temporary file: $!"); return; } - my $input = $env->{'psgi.input'}; my $buf; while (1) { my $r = $input->read($buf, 8192); @@ -243,7 +243,7 @@ sub input_to_file { err($env, "error seeking temporary file: $!"); return; } - return $in; + { 0 => fileno($in), -hold => $in }; } sub parse_cgi_headers { -- EW