about summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-03-26 08:21:29 +0000
committerEric Wong <e@yhbt.net>2020-03-26 23:47:10 +0000
commit5513e163236d8a64411050ae2e1f87aa8d24f023 (patch)
tree042b0ffbfa2d7f3590500eb0d0c2d39f3bc2a9ec
parent53d2c5c6d98465c33f6f257be0b99fcf5cbe38c7 (diff)
downloadpublic-inbox-5513e163236d8a64411050ae2e1f87aa8d24f023.tar.gz
Seeing the example config linkified, some users may inevitably
try to following it in a browser with a GET request.  Provide
a helpful message to inform users to use POST instead of
attempting to treat /$INBOX/$ALTID.sql.gz as a Message-Id.
-rw-r--r--lib/PublicInbox/WWW.pm2
-rw-r--r--lib/PublicInbox/WwwAltId.pm18
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 56d2c42a..275e509f 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -125,6 +125,8 @@ sub call {
                 get_vcs_object($ctx, $1, $2, $3);
         } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s\z!o) {
                 r301($ctx, $1, $2, 's/');
+        } elsif ($path_info =~ m!$INBOX_RE/(\w+)\.sql\.gz\z!o) {
+                get_altid_dump($ctx, $1, $2);
         # convenience redirects order matters
         } elsif ($path_info =~ m!$INBOX_RE/([^/]{2,})\z!o) {
                 r301($ctx, $1, $2);
diff --git a/lib/PublicInbox/WwwAltId.pm b/lib/PublicInbox/WwwAltId.pm
index a45d8061..263e884a 100644
--- a/lib/PublicInbox/WwwAltId.pm
+++ b/lib/PublicInbox/WwwAltId.pm
@@ -38,6 +38,7 @@ sub check_output {
 # and thus not usable from DBD::SQLite.
 sub sqldump ($$) {
         my ($ctx, $altid_pfx) = @_;
+        my $env = $ctx->{env};
         my $ibx = $ctx->{-inbox};
         my $altid_map = $ibx->altid_map;
         my $fn = $altid_map->{$altid_pfx};
@@ -47,6 +48,22 @@ sub sqldump ($$) {
 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);
+<pre>A POST request required to retrieve $altid_pfx.sql.gz
+
+        curl -XPOST -O $url
+
+or
+
+        curl -XPOST $url | \\
+                gzip -dc | \\
+                sqlite3 /path/to/$altid_pfx.sqlite3
+</pre>
+EOF
+        }
+
         eval { require PublicInbox::GzipFilter } or
                 return PublicInbox::WwwStream::oneshot($ctx, 501, \<<EOF);
 <pre>gzip output not available
@@ -73,7 +90,6 @@ EOF
 
         # TODO: use -readonly if available with newer sqlite3(1)
         my $qsp = PublicInbox::Qspawn->new([$sqlite3, $fn], undef, { 0 => $r });
-        my $env = $ctx->{env};
         $ctx->{altid_pfx} = $altid_pfx;
         $env->{'qspawn.filter'} = PublicInbox::GzipFilter->new;
         $qsp->psgi_return($env, undef, \&check_output, $ctx);