diff options
author | Eric Wong <e@80x24.org> | 2019-03-10 07:51:45 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-04-04 09:13:58 +0000 |
commit | 5cf5b6d19d931fce6053324b9a9540ad29487069 (patch) | |
tree | 00de4a946734ad456f305f394b5980833a36d56c /lib/PublicInbox | |
parent | 5af881d954a4ab14e08dd806dd4de1e9f26bfd12 (diff) | |
download | public-inbox-5cf5b6d19d931fce6053324b9a9540ad29487069.tar.gz |
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.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/GitHTTPBackend.pm | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index 5750d254..f6528c45 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 { |