From b60a668b43b0a279c2a1d621c009396bea1a4898 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 10 Apr 2014 20:02:34 +0000 Subject: cgi: /$LISTNAME/ and /$LISTNAME/index.html are equal 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 | 8 ++++++-- public-inbox-cgi | 2 +- t/cgi.t | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index a6c1b9c1..da4cc04a 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -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"; diff --git a/public-inbox-cgi b/public-inbox-cgi index cd79a4a7..828c94c1 100755 --- a/public-inbox-cgi +++ b/public-inbox-cgi @@ -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 a19f2cf1..93a48d00 100644 --- 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"); -- cgit v1.2.3-24-ge0c7