]> Sergey Matveev's repositories - public-inbox.git/commitdiff
qspawn: more generic command chaining
authorEric Wong <e@80x24.org>
Tue, 27 Dec 2022 12:51:55 +0000 (12:51 +0000)
committerEric Wong <e@80x24.org>
Tue, 27 Dec 2022 22:52:33 +0000 (22:52 +0000)
Move the chaining logic into qspawn so we can gracefully
try other commands when cgit or git-http-backend refuses
to service a request for us.

lib/PublicInbox/GitHTTPBackend.pm
lib/PublicInbox/Qspawn.pm

index 974a1831340c3581a3fc55a5e0b335b7055c22f3..e84d4ff802bf763697ee9937257ec84fc6b83c0f 100644 (file)
@@ -154,12 +154,9 @@ sub parse_cgi_headers { # {parse_hdr} for Qspawn
                delete $ctx->{env}->{'qspawn.wcb'};
                $ctx->{env}->{'plack.skip-deflater'} = 1; # prevent 2x gzip
                my $res = $ctx->{www}->coderepo->srv(\%ctx);
-               if (ref($res) eq 'CODE') {
-                       $res->(delete $ctx{env}->{'qspawn.wcb'});
-               } else { # ref($res) eq 'ARRAY'
-                       $ctx->{env}->{'qspawn.wcb'} = $ctx{env}->{'qspawn.wcb'};
-               }
-               $res; # non ARRAY ref for ->psgi_return_init_cb
+               # for ->psgi_return_init_cb:
+               $ctx->{env}->{'qspawn.wcb'} = $ctx{env}->{'qspawn.wcb'};
+               $res; # CODE or ARRAY ref
        } else {
                [ $code, \@h ]
        }
index 6e24538959517b00ec1179f87318a9d875ab3db8..9ca6b3dbbcc98c6a761e34fe4cc7e94f4a94ccd4 100644 (file)
@@ -237,7 +237,12 @@ sub psgi_return_init_cb {
                        $self->{rpipe}->close;
                        event_step($self);
                }
-               $wcb->($r) if ref($r) eq 'ARRAY';
+               if (ref($r) eq 'ARRAY') { # error
+                       $wcb->($r)
+               } elsif (ref($r) eq 'CODE') { # chain another command
+                       $r->($wcb)
+               }
+               # else do nothing
        } elsif ($async) {
                # done reading headers, handoff to read body
                my $fh = $wcb->($r); # scalar @$r == 2