user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH 2/5] wire up shorter, less ambiguous URLs
Date: Thu, 27 Aug 2015 04:33:59 +0000	[thread overview]
Message-ID: <1440650042-26176-3-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1440650042-26176-1-git-send-email-e@80x24.org>

We will prefer URLs without suffixes for now to avoid ambiguity
in case a Message-ID ends with ".html", ".txt", ".mbox.gz" or
any other suffix we may use.

Static file compatibility is preserved by using a trailing slash
as most servers can/will fall back to an index.html file in this
case.

For raw text files, we will follow gmane's lead with "/raw"
---
 lib/PublicInbox/WWW.pm | 13 ++++++++++---
 t/cgi.t                |  2 +-
 t/plack.t              | 19 +++++++++++++++++++
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 527d213..ca338fb 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -40,12 +40,18 @@ sub run {
 		invalid_list(\%ctx, $1) || get_atom(\%ctx);
 
 	# single-message pages
+	} elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)/\z!o) {
+		invalid_list_mid(\%ctx, $1, $2) || get_mid_html(\%ctx);
+	} elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)/raw\z!o) {
+		invalid_list_mid(\%ctx, $1, $2) || get_mid_txt(\%ctx);
 	} elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)\.txt\z!o) {
 		invalid_list_mid(\%ctx, $1, $2) || get_mid_txt(\%ctx);
 	} elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)\.html\z!o) {
 		invalid_list_mid(\%ctx, $1, $2) || get_mid_html(\%ctx);
 
 	# full-message page
+	} elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)/\z!o) {
+		invalid_list_mid(\%ctx, $1, $2) || get_full_html(\%ctx);
 	} elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\.html\z!o) {
 		invalid_list_mid(\%ctx, $1, $2) || get_full_html(\%ctx);
 
@@ -53,7 +59,8 @@ sub run {
 	} elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.html\z!o) {
 		invalid_list_mid(\%ctx, $1, $2) || get_thread(\%ctx);
 
-	} elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.mbox(\.gz)?\z!o) {
+	} elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)/mbox(\.gz)?\z!ox ||
+	         $path_info =~ m!$LISTNAME_RE/t/(\S+)\.mbox(\.gz)?\z!o) {
 		my $sfx = $3;
 		invalid_list_mid(\%ctx, $1, $2) ||
 			get_thread_mbox(\%ctx, $sfx);
@@ -325,8 +332,8 @@ sub msg_pfx {
 	"../f/$href.html";
 }
 
-# /$LISTNAME/t/$MESSAGE_ID.mbox           -> thread as mbox
-# /$LISTNAME/t/$MESSAGE_ID.mbox.gz        -> thread as gzipped mbox
+# /$LISTNAME/t/$MESSAGE_ID/mbox           -> thread as mbox
+# /$LISTNAME/t/$MESSAGE_ID/mbox.gz        -> thread as gzipped mbox
 # note: I'm not a big fan of other compression formats since they're
 # significantly more expensive on CPU than gzip and less-widely available,
 # especially on older systems.  Stick to zlib since that's what git uses.
diff --git a/t/cgi.t b/t/cgi.t
index e87f7dc..020dfe7 100644
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -183,7 +183,7 @@ EOF
 {
 	local $ENV{HOME} = $home;
 	local $ENV{PATH} = $main_path;
-	my $path = "/test/t/blahblah%40example.com.mbox.gz";
+	my $path = "/test/t/blahblah%40example.com/mbox.gz";
 	my $res = cgi_run($path);
 	like($res->{head}, qr/^Status: 501 /, "search not-yet-enabled");
 	my $indexed = system($index, $maindir) == 0;
diff --git a/t/plack.t b/t/plack.t
index 85dd337..ed41ab1 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -101,6 +101,25 @@ EOF
 			qr!link\s+href="\Q$pfx\E/m/blah%40example\.com\.html"!s,
 			'atom feed generated correct URL');
 	});
+
+	foreach my $t (qw(f m)) {
+		test_psgi($app, sub {
+			my ($cb) = @_;
+			my $pfx = 'http://example.com/test';
+			my $path = "/$t/blah%40example.com/";
+			my $res = $cb->(GET($pfx . $path));
+			is(200, $res->code, "success for $path");
+			like($res->content, qr!<title>hihi - Me</title>!,
+				"HTML returned");
+		});
+	}
+	test_psgi($app, sub {
+		my ($cb) = @_;
+		my $pfx = 'http://example.com/test';
+		my $res = $cb->(GET($pfx . '/m/blah%40example.com/raw'));
+		is(200, $res->code, 'success response received for /m/*/raw');
+		like($res->content, qr!\AFrom !, "mbox returned");
+	});
 }
 
 done_testing();
-- 
EW


  parent reply	other threads:[~2015-08-27  4:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27  4:33 [PATCH 0/5] prefer shorter, less-ambiguous URLs Eric Wong
2015-08-27  4:33 ` [PATCH 1/5] www: minor cleanups to shorten code Eric Wong
2015-08-27  4:33 ` Eric Wong [this message]
2015-08-27  4:34 ` [PATCH 3/5] mid: extract Message-ID from inside '<>' Eric Wong
2015-08-27  4:34 ` [PATCH 4/5] wire up to display non-suffixed Message-ID links Eric Wong
2015-08-27  4:34 ` [PATCH 5/5] implement legacy redirects for old URLs Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440650042-26176-3-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).