]> Sergey Matveev's repositories - public-inbox.git/commitdiff
cgi: /$LISTNAME/ and /$LISTNAME/index.html are equal
authorEric Wong <e@80x24.org>
Thu, 10 Apr 2014 20:02:34 +0000 (20:02 +0000)
committerEric Wong <e@80x24.org>
Fri, 11 Apr 2014 22:23:58 +0000 (22:23 +0000)
This prevents ambiguity when switching URLs between static
file servers and CGI.

The /$LISTNAME/index.html URL appearing in the wild is inevitable
because of our static file server support.  Worst yet, there's
no easy/consistent way to get all installations detect and 301
them to the shorter /$LISTNAME/.  So we make the CGI support
/$LISTNAME/index.html.

The downside of this is the potential duplicate entry in all caches.

lib/PublicInbox/Feed.pm
public-inbox-cgi
t/cgi.t

index a6c1b9c1e02b8a239edea53719af5e43785b50eb..da4cc04a940ef9794a1ad88ad428eda543977764 100644 (file)
@@ -116,8 +116,12 @@ sub get_feedopts {
        if ($cgi) {
                my $cgi_url = $cgi->self_url;
                $url_base = $cgi_url;
-               $url_base =~ s!/?(?:index|all)\.atom\.xml\z!!;
-               $rv{atomurl} = $cgi_url;
+               if ($url_base =~ s!/(?:|index\.html)?\z!!) {
+                       $rv{atomurl} = "$url_base/index.atom.xml";
+               } else {
+                       $url_base =~ s!/?(?:index|all)\.atom\.xml\z!!;
+                       $rv{atomurl} = $cgi_url;
+               }
        } else {
                $url_base = "http://example.com";
                $rv{atomurl} = "$url_base/index.atom.xml";
index cd79a4a7961c102b5f1960eeaf012d0a9b2484aa..828c94c1672d9753652d6012356025e2864c04b8 100755 (executable)
@@ -55,7 +55,7 @@ sub main {
        # top-level indices and feeds
        if ($path_info eq "/") {
                r404();
-       } elsif ($path_info =~ m!$LISTNAME_RE/?\z!o) {
+       } elsif ($path_info =~ m!$LISTNAME_RE(?:/|/index\.html)?\z!o) {
                invalid_list(\%ctx, $1) || get_index(\%ctx, $cgi, 1);
        } elsif ($path_info =~ m!$LISTNAME_RE/index\.atom\.xml\z!o) {
                invalid_list(\%ctx, $1) || get_atom(\%ctx, $cgi, 1);
diff --git a/t/cgi.t b/t/cgi.t
index a19f2cf11ab9fe8f367ce69ab942fa447846d48b..93a48d0079e431d0c1e8ff2b0cf09901f962ec78 100644 (file)
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -119,10 +119,13 @@ EOF
        local $ENV{HOME} = $home;
        my $res = cgi_run("/test/");
        like($res->{head}, qr/Status: 200 OK/, "index returns 200");
+
+       my $idx = cgi_run("/test/index.html");
+       is_deeply($res, $idx,
+               '/$LISTNAME/ and /$LISTNAME/index.html are identical');
        # more checks in t/feed.t
 }
 
-
 {
        local $ENV{HOME} = $home;
        my $res = cgi_run("/test/m/blahblah\@example.com.txt");