]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wwwaltid: inform users to use POST instead of GET
authorEric Wong <e@yhbt.net>
Thu, 26 Mar 2020 08:21:29 +0000 (08:21 +0000)
committerEric Wong <e@yhbt.net>
Thu, 26 Mar 2020 23:47:10 +0000 (23:47 +0000)
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.

lib/PublicInbox/WWW.pm
lib/PublicInbox/WwwAltId.pm

index 56d2c42a41cd8eafd37444e68495644f28a80388..275e509f2f1136ad62d129e114b245f9c8b75cd4 100644 (file)
@@ -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);
index a45d8061069e9402d8ab72c9d3af1f09895aa356..263e884aa445c92b588c1637546166b343205399 100644 (file)
@@ -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);