From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 9B6071FA3D for ; Mon, 23 Oct 2023 08:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1698050920; bh=g0Ubvmf9plDGwYWVRby+T9k87Nu+WNeAnA32g+RUhQI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=M/PCdkYMtnCCY6eeaxPnR1DgpfUOjhfe3qMdeSz4gz9TwbLa/WgTx60XSs5E6O9xQ xMabI+1G3fUyqbOAAJDccqoMBGAMucvh+moMNzBedeHlwaajjxl4ueD8fjf3jFdhyY VNDNaV7WDWgx8B0RtO7TCFbu6DU4xMlLv318OFQ0= From: Eric Wong To: spew@80x24.org Subject: [PATCH 17/18] qspawn: use WwwStatic for fallbacks and error code Date: Mon, 23 Oct 2023 08:48:36 +0000 Message-ID: <20231023084837.2804687-17-e@80x24.org> In-Reply-To: <20231023084837.2804687-1-e@80x24.org> References: <20231023084837.2804687-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This ensures we set directives to disable caching since errors are always transient. --- lib/PublicInbox/Qspawn.pm | 17 +++++++++-------- 1 file 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 <{cmd}} ($self->{psgi_env}->{REQUEST_URI}) EOM - $ret = r500(); + $ret = psgi_status_err(); } } else { carp <{cmd}} ($self->{psgi_env}->{REQUEST_URI}) EOM - $ret = r500(); + $ret = psgi_status_err(); } $ret; # undef if headers incomplete }