From 1988d730c0088e8b1f6193650c7ee929df8a2ed7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Jan 2020 03:09:30 +0000 Subject: config: support multi-value inbox.*.*url Since the beginning of this project, we've implicitly supported inboxes with multiple URLs by relying on the Host: header sent by the client ($env->{HTTP_HOST}). We now offer the option to explicitly configure multiple URLs for every inbox along with the ability to do a best-effort match for matching hostnames. --- lib/PublicInbox/Config.pm | 7 ++++--- lib/PublicInbox/Hval.pm | 6 ++++++ lib/PublicInbox/Inbox.pm | 2 +- lib/PublicInbox/WwwListing.pm | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 8ecf549d..ffc31f83 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -362,8 +362,8 @@ sub _fill { my ($self, $pfx) = @_; my $ibx = {}; - foreach my $k (qw(inboxdir filter url newsgroup - infourl watch watchheader httpbackendmax + foreach my $k (qw(inboxdir filter newsgroup + watch watchheader httpbackendmax replyto feedmax nntpserver indexlevel)) { my $v = $self->{"$pfx.$k"}; $ibx->{$k} = $v if defined $v; @@ -383,7 +383,8 @@ sub _fill { } # TODO: more arrays, we should support multi-value for # more things to encourage decentralization - foreach my $k (qw(address altid nntpmirror coderepo hide listid)) { + foreach my $k (qw(address altid nntpmirror coderepo hide listid url + infourl)) { if (defined(my $v = $self->{"$pfx.$k"})) { $ibx->{$k} = _array($v); } diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index 4a79439f..cd3a4df3 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -86,6 +86,12 @@ sub raw { sub prurl { my ($env, $u) = @_; + if (ref($u) eq 'ARRAY') { + my $h = $env->{HTTP_HOST} // $env->{SERVER_NAME}; + my @host_match = grep(/\b\Q$h\E\b/, @$u); + $u = $host_match[0] // $u->[0]; + # fall through to below: + } index($u, '//') == 0 ? "$env->{'psgi.url_scheme'}:$u" : $u; } diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index f294c0d5..a3cdcbc0 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -252,7 +252,7 @@ sub base_url { } else { # either called from a non-PSGI environment (e.g. NNTP/POP3) $self->{-base_url} ||= do { - my $url = $self->{url} or return undef; + my $url = $self->{url}->[0] or return undef; # expand protocol-relative URLs to HTTPS if we're # not inside a web server $url = "https:$url" if $url =~ m!\A//!; diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm index 1faade6c..4f076b7d 100644 --- a/lib/PublicInbox/WwwListing.pm +++ b/lib/PublicInbox/WwwListing.pm @@ -32,7 +32,7 @@ sub list_all ($$$) { sub list_match_domain_i { my ($ibx, $arg) = @_; my ($list, $hide_key, $re) = @$arg; - if (!$ibx->{-hide}->{$hide_key} && $ibx->{url} =~ $re) { + if (!$ibx->{-hide}->{$hide_key} && grep($re, @{$ibx->{url}})) { push @$list, $ibx; } } @@ -90,7 +90,7 @@ sub ibx_entry { ${\$ibx->description} if (defined(my $info_url = $ibx->{infourl})) { - $tmp .= ' ' . $info_url . "\n"; + $tmp .= ' ' . PublicInbox::Hval::prurl($env, $info_url) . "\n"; } $tmp; } -- cgit v1.2.3-24-ge0c7