]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: fix non-empty SCRIPT_NAME handling for PSGI mounts
authorEric Wong <e@80x24.org>
Wed, 4 Jan 2023 10:34:03 +0000 (10:34 +0000)
committerEric Wong <e@80x24.org>
Thu, 5 Jan 2023 09:58:27 +0000 (09:58 +0000)
When using the `mount' directive in PSGI (Plack::App::URLMap),
SCRIPT_NAME still needs to use a trailing slash before it can
be joined with another URL.

lib/PublicInbox/Git.pm

index c7f82ba2f4eaba45a301a936ddd2d32b2722fa6c..d8468b4fb381a16173b6459c68b23e28f1fa7b29 100644 (file)
@@ -477,10 +477,10 @@ sub local_nick ($) {
 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;
+       my $sn = $env->{SCRIPT_NAME} // '';
+       "$env->{'psgi.url_scheme'}://$host_port$sn/$url";
 }
 
 sub base_url { # for coderepos, PSGI-only