From 5af881d954a4ab14e08dd806dd4de1e9f26bfd12 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 8 Mar 2019 01:21:22 +0000 Subject: support publicinbox.cgitrc directive We can save admins the trouble of declaring [coderepo "..."] sections in the public-inbox config by parsing the cgitrc directly. Macro expansion (e.g. $HTTP_HOST) expansion is not supported, yet; but may be in the future. --- lib/PublicInbox/Git.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/Git.pm') diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 265c3fb4..8a96e10c 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -288,10 +288,19 @@ sub src_blob_url { local_nick($self); } +sub host_prefix_url ($$) { + my ($env, $url) = @_; + return $url if index($url, '//') >= 0; + my $scheme = $env->{'psgi.url_scheme'}; + my $host_port = $env->{HTTP_HOST} || + "$env->{SERVER_NAME}:$env->{SERVER_PORT}"; + "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/') . $url; +} + sub pub_urls { - my ($self) = @_; + my ($self, $env) = @_; if (my $urls = $self->{cgit_url}) { - return @$urls; + return map { host_prefix_url($env, $_) } @$urls; } local_nick($self); } -- cgit v1.2.3-24-ge0c7