From 19e00ca1a6aab8e59f74241fcdfbb768785ff2ff Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 15 May 2016 06:31:50 +0000 Subject: www: fix for running under mount paths We try to avoid issues like these by using relative URLs in hrefs, but we can't avoid the problem with Location: for redirects and Atom feeds which are likely to be rehosted elsewhere. We also reorder some of the code to work around a weird issue on the psgi-plack mailing list: <20160516073750.GA11931@dcvr.yhbt.net> (Somewhere on https://groups.google.com/group/psgi-plack but it's probably not bookmarkable) --- lib/PublicInbox/WWW.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/PublicInbox/WWW.pm') diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 94ab032f..95288a7b 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -39,7 +39,7 @@ sub run { sub call { my ($self, $env) = @_; my $cgi = Plack::Request->new($env); - my $ctx = { cgi => $cgi, pi_config => $self->{pi_config} }; + my $ctx = {cgi => $cgi, pi_config => $self->{pi_config}, www => $self}; my $path_info = $cgi->path_info; my $method = $cgi->method; @@ -124,7 +124,7 @@ sub r { [ $_[0], ['Content-Type' => 'text/plain'], [ join(' ', @_, "\n") ] ] } # returns undef if valid, array ref response if invalid sub invalid_inbox { - my ($self, $ctx, $inbox, $mid) = @_; + my ($self, $ctx, $inbox) = @_; my $obj = $ctx->{pi_config}->lookup_name($inbox); if (defined $obj) { $ctx->{git_dir} = $obj->{mainrepo}; @@ -144,7 +144,7 @@ sub invalid_inbox { # returns undef if valid, array ref response if invalid sub invalid_inbox_mid { my ($self, $ctx, $inbox, $mid) = @_; - my $ret = invalid_inbox($self, $ctx, $inbox, $mid); + my $ret = invalid_inbox($self, $ctx, $inbox); return $ret if $ret; $ctx->{mid} = $mid = uri_unescape($mid); @@ -382,9 +382,14 @@ sub legacy_redirects { sub r301 { my ($ctx, $inbox, $mid, $suffix) = @_; my $cgi = $ctx->{cgi}; - my $url; + my $obj = $ctx->{-inbox}; + unless ($obj) { + my $r404 = invalid_inbox($ctx->{www}, $ctx, $inbox); + return $r404 if $r404; + $obj = $ctx->{-inbox}; + } + my $url = $obj->base_url($cgi); my $qs = $cgi->env->{QUERY_STRING}; - $url = $cgi->base->as_string . $inbox . '/'; $url .= (uri_escape_utf8($mid) . '/') if (defined $mid); $url .= $suffix if (defined $suffix); $url .= "?$qs" if $qs ne ''; -- cgit v1.2.3-24-ge0c7