about summary refs log tree commit homepage
path: root/lib/PublicInbox/RepobrowseBase.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-01-20 22:35:23 +0000
committerEric Wong <e@80x24.org>2016-04-05 18:58:27 +0000
commitf08dc18b4f5b3aa7a43bfa9ce754b23028f5babb (patch)
treee0632c5e755fb28fecc68aab02275b873de2ec0d /lib/PublicInbox/RepobrowseBase.pm
parentb3bc0d722aacdad5ac5e8ee7c32bda9c87d3052b (diff)
downloadpublic-inbox-f08dc18b4f5b3aa7a43bfa9ce754b23028f5babb.tar.gz
We shall save clients the overhead of making extra HTTP requests
to follow partial paths.  This ought to improve cache hit
effectiveness on both the server and client side by reducing
the potential different pages we may set.
Diffstat (limited to 'lib/PublicInbox/RepobrowseBase.pm')
-rw-r--r--lib/PublicInbox/RepobrowseBase.pm40
1 files changed, 39 insertions, 1 deletions
diff --git a/lib/PublicInbox/RepobrowseBase.pm b/lib/PublicInbox/RepobrowseBase.pm
index 14926d70..dd854ffc 100644
--- a/lib/PublicInbox/RepobrowseBase.pm
+++ b/lib/PublicInbox/RepobrowseBase.pm
@@ -60,7 +60,7 @@ sub mime_type {
 sub html_start {
         my ($self, $req, $title_html, $opts) = @_;
         my $desc = $req->{repo_info}->{desc_html};
-        my $meta;
+        my $meta = '';
 
         if ($opts) {
                 my @robots;
@@ -76,4 +76,42 @@ sub html_start {
                 "</head><body><pre><b>$desc</b>";
 }
 
+sub r {
+        my ($self, $status, $req, @extra) = @_;
+        my @h;
+
+        my $body = '';
+        if ($status == 301 || $status == 302) {
+                # The goal is to be able to make redirects like we make
+                # <a href=> tags with '../'
+                my $cgi = $req->{cgi};
+                my $base;
+                $base = ref($cgi) eq 'CGI' ? $cgi->url(-base).'/' : $cgi->base;
+                my ($redir) = @extra;
+                if ($redir =~ m!\A\.\./!) { # relative redirect
+                        my @orig = split(m!/+!, $cgi->path_info, -1);
+                        shift @orig; # drop leading '/'
+                        my @dest = split(m!/+!, $redir);
+
+                        while ($dest[0] eq '..') {
+                                pop @orig;
+                                shift @dest;
+                        }
+                        my $end = '';
+                        $end = pop @dest if $dest[-1] =~ /\A[#\?]/;
+                        $redir = $base . join('/', @orig, @dest) . $end;
+                } else {
+                        $redir = $base . '/' . $redir;
+                }
+                push @h, qw(Content-Type text/plain Location), $redir;
+
+                # mainly for curl (no-'-L') users:
+                $body = "Redirecting to $redir\n";
+        } else {
+                die "not implemented, yet: $status";
+        }
+
+        [ $status, \@h, [ $body ] ]
+}
+
 1;