about summary refs log tree commit homepage
path: root/lib/PublicInbox/GitHTTPBackend.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-10-05 22:29:40 +0000
committerEric Wong <e@80x24.org>2022-10-07 07:27:26 +0000
commit26037c85f73de67197af1987e4c0fa4786ac1e31 (patch)
tree52d7f462fe42bd091fca039dc2956c0707ff5a4f /lib/PublicInbox/GitHTTPBackend.pm
parent9fe2348fc4a3462b2de0483b1a1f4baf6edff14c (diff)
downloadpublic-inbox-26037c85f73de67197af1987e4c0fa4786ac1e31.tar.gz
We can't rely on 3-element array response when calling
WwwCoderepo for ViewVCS endpoints since that uses Qspawn
internally.  Thus, we have to allow two Qspawn objects to run in
parallel and ensure `qspawn.wcb' only gets called once, so we
end up duplicating the entire $ctx to ensure this.
Diffstat (limited to 'lib/PublicInbox/GitHTTPBackend.pm')
-rw-r--r--lib/PublicInbox/GitHTTPBackend.pm19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index ba3a8f20..61a13560 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # when no endpoints match, fallback to this and serve a static file
@@ -132,7 +132,7 @@ sub input_prepare {
 }
 
 sub parse_cgi_headers {
-        my ($r, $bref) = @_;
+        my ($r, $bref, $ctx) = @_;
         return r(500) unless defined $r && $r >= 0;
         $$bref =~ s/\A(.*?)\r?\n\r?\n//s or return $r == 0 ? r(500) : undef;
         my $h = $1;
@@ -146,7 +146,20 @@ sub parse_cgi_headers {
                         push @h, $k, $v;
                 }
         }
-        [ $code, \@h ]
+
+        # fallback to WwwCoderepo if cgit 404s.  Duplicating $ctx prevents
+        # ->finalize from the current Qspawn from using qspawn.wcb
+        if ($code == 404 && $ctx->{www} && !$ctx->{_coderepo_tried}++) {
+                my %ctx = %$ctx;
+                $ctx{env} = +{ %{$ctx->{env}} };
+                delete $ctx->{env}->{'qspawn.wcb'};
+                $ctx->{env}->{'plack.skip-deflater'} = 1; # prevent 2x gzip
+                my $res = $ctx->{www}->coderepo->srv(\%ctx);
+                $res->(delete $ctx{env}->{'qspawn.wcb'}) if ref($res) eq 'CODE';
+                $res; # non ARRAY ref for ->psgi_return_init_cb
+        } else {
+                [ $code, \@h ]
+        }
 }
 
 1;