]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wire up shorter, less ambiguous URLs
authorEric Wong <e@80x24.org>
Thu, 27 Aug 2015 04:33:59 +0000 (04:33 +0000)
committerEric Wong <e@80x24.org>
Thu, 27 Aug 2015 06:04:51 +0000 (06:04 +0000)
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
t/cgi.t
t/plack.t

index 527d2131a27f894c9e68678e53a34318508a674d..ca338fb41dfee142132414c45a283b475117aa51 100644 (file)
@@ -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 e87f7dcae6df6d2bb54759c5fabc58df23eb3f5d..020dfe7eeea81c6c9d92de6e28f8d4c6ab08b5d6 100644 (file)
--- 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;
index 85dd337dd11d6fe55a0aa39a94c58c38996ecf5c..ed41ab17afea6a94e6ea49bef3bd01bc7e875877 100644 (file)
--- 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();