user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 3/3] wwwaltid: inform users to use POST instead of GET
  2020-03-26  8:21  4% [PATCH 0/3] wwwaltid: add pointers for usability Eric Wong
@ 2020-03-26  8:21  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2020-03-26  8:21 UTC (permalink / raw)
  To: meta

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      |  2 ++
 lib/PublicInbox/WwwAltId.pm | 18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

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);

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/3] wwwaltid: add pointers for usability
@ 2020-03-26  8:21  4% Eric Wong
  2020-03-26  8:21  7% ` [PATCH 3/3] wwwaltid: inform users to use POST instead of GET Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2020-03-26  8:21 UTC (permalink / raw)
  To: meta

Provide helpful hints and pointers in existing config example
to reproduce altid DBs when mirroring

Eric Wong (3):
  inbox: altid_map becomes a method
  wwwtext: show altid instructions in config
  wwwaltid: inform users to use POST instead of GET

 lib/PublicInbox/Inbox.pm    | 15 +++++++++++++++
 lib/PublicInbox/WWW.pm      |  3 +++
 lib/PublicInbox/WwwAltId.pm | 32 ++++++++++++++++++--------------
 lib/PublicInbox/WwwText.pm  | 20 ++++++++++++++++++--
 4 files changed, 54 insertions(+), 16 deletions(-)


^ permalink raw reply	[relevance 4%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-03-26  8:21  4% [PATCH 0/3] wwwaltid: add pointers for usability Eric Wong
2020-03-26  8:21  7% ` [PATCH 3/3] wwwaltid: inform users to use POST instead of GET 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).