]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wwwstream::oneshot => html_oneshot
authorEric Wong <e@yhbt.net>
Mon, 30 Mar 2020 05:18:42 +0000 (00:18 -0500)
committerEric Wong <e@yhbt.net>
Mon, 30 Mar 2020 17:49:28 +0000 (17:49 +0000)
And use Exporter to make our life easier, since WwwAltId was
using a non-existent PublicInbox::WwwResponse namespace in error
paths which doesn't get noticed by `perl -c' or exercised by
tests on normal systems.

Fixes: 6512b1245ebc6fe3 ("www: add endpoint to retrieve altid dumps")
lib/PublicInbox/ExtMsg.pm
lib/PublicInbox/Mbox.pm
lib/PublicInbox/ViewVCS.pm
lib/PublicInbox/WwwAltId.pm
lib/PublicInbox/WwwStream.pm

index a14eddf6cd8ce1651f357a50b35e5bae7e12f753..1d17c2ce673c230ecfe69fbdaf0a0008be7abaa1 100644 (file)
@@ -9,7 +9,7 @@ package PublicInbox::ExtMsg;
 use strict;
 use warnings;
 use PublicInbox::Hval qw(ascii_html prurl mid_href);
-use PublicInbox::WwwStream;
+use PublicInbox::WwwStream qw(html_oneshot);
 use PublicInbox::Smsg;
 our $MIN_PARTIAL_LEN = 16;
 
@@ -159,7 +159,7 @@ sub ext_msg {
        $ctx->{-html_tip} = $s .= '</pre>';
        $ctx->{-title_html} = $title;
        $ctx->{-upfx} = '../';
-       PublicInbox::WwwStream::oneshot($ctx, $code);
+       html_oneshot($ctx, $code);
 }
 
 sub ext_urls {
@@ -197,7 +197,7 @@ sub exact {
                                        qq(<a\nhref="$u$href/">$u$html/</a>\n)
                                } @$found),
                        $ext_urls, '</pre>');
-       PublicInbox::WwwStream::oneshot($ctx, $code);
+       html_oneshot($ctx, $code);
 }
 
 1;
index 46964bbb77cc5e49584dd35ea67c77ecaa221356..3013dc91d9e5609ad6de78a0b754bbb7076c72df 100644 (file)
@@ -13,6 +13,7 @@ use warnings;
 use PublicInbox::MID qw/mid_escape/;
 use PublicInbox::Hval qw/to_filename/;
 use PublicInbox::Smsg;
+use PublicInbox::WwwStream qw(html_oneshot);
 use Email::Simple;
 use Email::MIME::Encode;
 
@@ -236,7 +237,7 @@ sub mbox_all {
 }
 
 sub need_gzip {
-       PublicInbox::WwwStream::oneshot($_[0], 501, \<<EOF);
+       html_oneshot($_[0], 501, \<<EOF);
 <pre>gzipped mbox not available
 
 The administrator needs to install the Compress::Raw::Zlib Perl module
index 6714e67cdabf6556c97aca3b40e0c48c94332040..069937c132af90d6d9fff3c80e55c092e0dc3b49 100644 (file)
@@ -18,7 +18,7 @@ use strict;
 use warnings;
 use bytes (); # only for bytes::length
 use PublicInbox::SolverGit;
-use PublicInbox::WwwStream;
+use PublicInbox::WwwStream qw(html_oneshot);
 use PublicInbox::Linkify;
 use PublicInbox::Tmpfile;
 use PublicInbox::Hval qw(ascii_html to_filename);
@@ -35,7 +35,7 @@ sub html_page ($$$) {
        my ($ctx, $code, $strref) = @_;
        my $wcb = delete $ctx->{-wcb};
        $ctx->{-upfx} = '../../'; # from "/$INBOX/$OID/s/"
-       my $res = PublicInbox::WwwStream::oneshot($ctx, $code, $strref);
+       my $res = html_oneshot($ctx, $code, $strref);
        $wcb ? $wcb->($res) : $res;
 }
 
index 263e884aa445c92b588c1637546166b343205399..630ed6861cfc8d6ff21a167dfbd9a14ea95bca5b 100644 (file)
@@ -5,13 +5,13 @@
 package PublicInbox::WwwAltId;
 use strict;
 use PublicInbox::Qspawn;
-use PublicInbox::WwwStream;
+use PublicInbox::WwwStream qw(html_oneshot);
 use PublicInbox::AltId;
 use PublicInbox::Spawn qw(which);
 our $sqlite3 = $ENV{SQLITE3};
 
 sub sqlite3_missing ($) {
-       PublicInbox::WwwResponse::oneshot($_[0], 501, \<<EOF);
+       html_oneshot($_[0], 501, \<<EOF);
 <pre>sqlite3 not available
 
 The administrator needs to install the sqlite3(1) binary
@@ -22,11 +22,11 @@ EOF
 
 sub check_output {
        my ($r, $bref, $ctx) = @_;
-       return PublicInbox::WwwResponse::oneshot($ctx, 500) if !defined($r);
+       return html_oneshot($ctx, 500) if !defined($r);
        if ($r == 0) {
                my $err = eval { $ctx->{env}->{'psgi.errors'} } // \*STDERR;
                $err->print("unexpected EOF from sqlite3\n");
-               return PublicInbox::WwwResponse::oneshot($ctx, 501);
+               return html_oneshot($ctx, 501);
        }
        [200, [ qw(Content-Type application/gzip), 'Content-Disposition',
                "inline; filename=$ctx->{altid_pfx}.sql.gz" ] ]
@@ -43,14 +43,14 @@ sub sqldump ($$) {
        my $altid_map = $ibx->altid_map;
        my $fn = $altid_map->{$altid_pfx};
        unless (defined $fn) {
-               return PublicInbox::WwwStream::oneshot($ctx, 404, \<<EOF);
+               return html_oneshot($ctx, 404, \<<EOF);
 <pre>`$altid_pfx' is not a valid altid for this inbox</pre>
 EOF
        }
 
        if ($env->{REQUEST_METHOD} ne 'POST') {
                my $url = $ibx->base_url($ctx->{env}) . "$altid_pfx.sql.gz";
-               return PublicInbox::WwwStream::oneshot($ctx, 405, \<<EOF);
+               return html_oneshot($ctx, 405, \<<EOF);
 <pre>A POST request required to retrieve $altid_pfx.sql.gz
 
        curl -XPOST -O $url
@@ -65,7 +65,7 @@ EOF
        }
 
        eval { require PublicInbox::GzipFilter } or
-               return PublicInbox::WwwStream::oneshot($ctx, 501, \<<EOF);
+               return html_oneshot($ctx, 501, \<<EOF);
 <pre>gzip output not available
 
 The administrator needs to install the Compress::Raw::Zlib Perl module
@@ -73,7 +73,7 @@ to support gzipped sqlite3 dumps.</pre>
 EOF
        $sqlite3 //= which('sqlite3');
        if (!defined($sqlite3)) {
-               return PublicInbox::WwwStream::oneshot($ctx, 501, \<<EOF);
+               return html_oneshot($ctx, 501, \<<EOF);
 <pre>sqlite3 not available
 
 The administrator needs to install the sqlite3(1) binary
index 985e02622048b4a2ada72510aa84d4ab6273d7be..915a71ba0bd82df950ee498f03c9a2c078a78a79 100644 (file)
@@ -9,6 +9,8 @@
 package PublicInbox::WwwStream;
 use strict;
 use warnings;
+use base qw(Exporter);
+our @EXPORT_OK = qw(html_oneshot);
 use bytes (); # length
 use PublicInbox::Hval qw(ascii_html prurl);
 our $TOR_URL = 'https://www.torproject.org/';
@@ -170,7 +172,7 @@ sub getline {
        delete $self->{cb} ? _html_end($self) : undef;
 }
 
-sub oneshot {
+sub html_oneshot ($$;$) {
        my ($ctx, $code, $sref) = @_;
        my $self = bless {
                ctx => $ctx,