about summary refs log tree commit homepage
path: root/lib/PublicInbox/Git.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-03-08 01:21:22 +0000
committerEric Wong <e@80x24.org>2019-04-04 09:13:58 +0000
commit5af881d954a4ab14e08dd806dd4de1e9f26bfd12 (patch)
tree12e5a0286b841065671a7b3cd0fcfd4db80625fe /lib/PublicInbox/Git.pm
parent721368cd04bfbd03c0d9173fff633ae34f16409a (diff)
downloadpublic-inbox-5af881d954a4ab14e08dd806dd4de1e9f26bfd12.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r--lib/PublicInbox/Git.pm13
1 files changed, 11 insertions, 2 deletions
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);
 }