diff options
author | Eric Wong <e@80x24.org> | 2016-05-15 06:31:50 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-05-16 07:52:56 +0000 |
commit | 19e00ca1a6aab8e59f74241fcdfbb768785ff2ff (patch) | |
tree | a88da5cdd782b52672bb421afe2a96bfc1bfa194 /lib/PublicInbox/Inbox.pm | |
parent | f22bbb56cf44c6864d53cf27746f9cafc12e05c1 (diff) | |
download | public-inbox-19e00ca1a6aab8e59f74241fcdfbb768785ff2ff.tar.gz |
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)
Diffstat (limited to 'lib/PublicInbox/Inbox.pm')
-rw-r--r-- | lib/PublicInbox/Inbox.pm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 5d9fdb36..4bcab96f 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -64,6 +64,7 @@ sub cloneurl { $self->{cloneurl} = \@url; } +# TODO: can we remove this? sub footer_html { my ($self) = @_; my $footer = $self->{footer}; @@ -73,4 +74,23 @@ sub footer_html { $self->{footer} = $footer; } +sub base_url { + my ($self, $prq) = @_; # Plack::Request + if (defined $prq) { + my $url = $prq->base->as_string; + $url .= '/' if $url !~ m!/\z!; # for mount in Plack::Builder + $url .= $self->{name} . '/'; + } else { + # either called from a non-PSGI environment (e.g. NNTP/POP3) + $self->{-base_url} ||= do { + my $url = $self->{url}; + # expand protocol-relative URLs to HTTPS if we're + # not inside a web server + $url = "https:$url" if $url =~ m!\A//!; + $url .= '/' if $url !~ m!/\z!; + $url; + }; + } +} + 1; |