about summary refs log tree commit homepage
path: root/lib/PublicInbox/Qspawn.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-25 00:29:40 +0000
committerEric Wong <e@80x24.org>2023-10-25 07:28:42 +0000
commit05c5c40b6f5754c9afe2dedf8d345b26415f0011 (patch)
treecdc132947614456131a4fc9341c9f20cc02e8ca5 /lib/PublicInbox/Qspawn.pm
parent3e634c22ceff4736d3c34d3496e7e5519e6ef356 (diff)
downloadpublic-inbox-05c5c40b6f5754c9afe2dedf8d345b26415f0011.tar.gz
This ensures we set directives to disable caching since
errors are always transient.
Diffstat (limited to 'lib/PublicInbox/Qspawn.pm')
-rw-r--r--lib/PublicInbox/Qspawn.pm17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index a6e1d58b..0bb02081 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -74,6 +74,11 @@ sub _do_spawn {
         finish($self, $@) if $@;
 }
 
+sub psgi_status_err { # Qspawn itself is useful w/o PSGI
+        require PublicInbox::WwwStatic;
+        PublicInbox::WwwStatic::r($_[0] // 500);
+}
+
 sub finalize ($;$) {
         my ($self, $opt) = @_;
 
@@ -104,9 +109,7 @@ 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($code));
+                $wcb->(psgi_status_err($env->{'qspawn.fallback'}));
         }
 }
 
@@ -209,8 +212,6 @@ sub yield_pass {
         $self->{qfh} = $qfh; # keep $ipipe open
 }
 
-sub r500 () { [ 500, [], [ "Internal error\n" ] ] }
-
 sub parse_hdr_done ($$) {
         my ($self) = @_;
         my $ret;
@@ -220,18 +221,18 @@ sub parse_hdr_done ($$) {
                 $ret = eval { $ph_cb->(length($_[-1]), $bref, @ph_arg) };
                 if ($@) {
                         carp "parse_hdr (@{$self->{cmd}}): $@\n";
-                        $ret = r500();
+                        $ret = psgi_status_err();
                 } elsif (!$ret && $_[-1] eq '') {
                         carp <<EOM;
 EOF parsing headers from @{$self->{cmd}} ($self->{psgi_env}->{REQUEST_URI})
 EOM
-                        $ret = r500();
+                        $ret = psgi_status_err();
                 }
         } else {
                 carp <<EOM;
 E: parsing headers: $! from @{$self->{cmd}} ($self->{psgi_env}->{REQUEST_URI})
 EOM
-                $ret = r500();
+                $ret = psgi_status_err();
         }
         $ret; # undef if headers incomplete
 }