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 70CDE1FA4F for ; Wed, 25 Oct 2023 00:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1698193792; bh=g0Ubvmf9plDGwYWVRby+T9k87Nu+WNeAnA32g+RUhQI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=1EesKPqiEX/2rOg+hoKoKGCYcR86PznxkcpXVJ9cj9pM/iuU2al+rrOOxA1508K5y lLqUiMyQJoBd20QlkfVG86uJtFqL4uTh0cnAF64BI8NfEogUM/j7jC7HFFsqlrd5ow Ej/iobXASOijGQUmXWYR51Wp9lYJtnCrkq4kBW0Q= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 17/26] qspawn: use WwwStatic for fallbacks and error code Date: Wed, 25 Oct 2023 00:29:40 +0000 Message-ID: <20231025002949.3092193-18-e@80x24.org> In-Reply-To: <20231025002949.3092193-1-e@80x24.org> References: <20231025002949.3092193-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 }