* [PATCH] wwwstream::oneshot => html_oneshot
@ 2020-03-30 5:18 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-03-30 5:18 UTC (permalink / raw)
To: meta
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 | 6 +++---
lib/PublicInbox/Mbox.pm | 3 ++-
lib/PublicInbox/ViewVCS.pm | 4 ++--
lib/PublicInbox/WwwAltId.pm | 16 ++++++++--------
lib/PublicInbox/WwwStream.pm | 4 +++-
5 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index a14eddf6..1d17c2ce 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -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;
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 46964bbb..3013dc91 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -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
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 6714e67c..069937c1 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -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;
}
diff --git a/lib/PublicInbox/WwwAltId.pm b/lib/PublicInbox/WwwAltId.pm
index 263e884a..630ed686 100644
--- a/lib/PublicInbox/WwwAltId.pm
+++ b/lib/PublicInbox/WwwAltId.pm
@@ -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
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 985e0262..915a71ba 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -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,
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-03-30 5:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 5:18 [PATCH] wwwstream::oneshot => html_oneshot Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).