]> Sergey Matveev's repositories - public-inbox.git/commitdiff
qspawn: use fallback response code from CGI program
authorEric Wong <e@80x24.org>
Fri, 6 Jan 2023 10:10:50 +0000 (10:10 +0000)
committerEric Wong <e@80x24.org>
Fri, 6 Jan 2023 10:24:15 +0000 (10:24 +0000)
Prefer to use the original (cgit||git-http-backend) HTTP
response code if our fallback to WwwCoderepo fails.  404
codes is typically more appropriate than 500 for these things.

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

index 5b879871bbb1d7c9b732b087d88b639526fb64c9..744324294917df02bd07166a8d4e9423714b871d 100644 (file)
@@ -151,6 +151,7 @@ sub parse_cgi_headers { # {parse_hdr} for Qspawn
        if ($code == 404 && $ctx->{www} && !$ctx->{_coderepo_tried}++) {
                my $wcb = delete $ctx->{env}->{'qspawn.wcb'};
                $ctx->{env}->{'plack.skip-deflater'} = 1; # prevent 2x gzip
+               $ctx->{env}->{'qspawn.fallback'} = $code;
                my $res = $ctx->{www}->coderepo->srv($ctx);
                # for ->psgi_return_init_cb
                $ctx->{env}->{'qspawn.wcb'} = $wcb;
index ab0ef25c5611f3e645a4f4e593ae143ee94291a6..f8cbffcb359b74629a888119bcbba4237335d0ad 100644 (file)
@@ -109,8 +109,9 @@ sub finalize ($$) {
        return if $self->{passed}; # another command chained it
        if (my $wcb = delete $env->{'qspawn.wcb'}) {
                # have we started writing, yet?
+               my $code = delete $env->{'qspawn.fallback'} // 500;
                require PublicInbox::WwwStatic;
-               $wcb->(PublicInbox::WwwStatic::r(500));
+               $wcb->(PublicInbox::WwwStatic::r($code));
        }
 }