]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
www: move more logic into path_info_raw
[public-inbox.git] / lib / PublicInbox / WWW.pm
index 9021cb528e5f8da398e28d79c6ee7bbae787566b..13b66ee62be8413344435785809e861e82338930 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Main web interface for mailing list archives
@@ -15,7 +15,6 @@ use 5.010_001;
 use strict;
 use warnings;
 use bytes (); # only for bytes::length
-use Plack::Util;
 use PublicInbox::Config;
 use PublicInbox::Hval;
 use URI::Escape qw(uri_unescape);
@@ -43,15 +42,17 @@ sub run {
        PublicInbox::WWW->new->call($req->env);
 }
 
+# PATH_INFO is decoded, and we want the undecoded original
 my %path_re_cache;
-
-sub path_re ($) {
-       my $sn = $_[0]->{SCRIPT_NAME};
-       $path_re_cache{$sn} ||= do {
+sub path_info_raw ($) {
+       my ($env) = @_;
+       my $sn = $env->{SCRIPT_NAME};
+       my $re = $path_re_cache{$sn} ||= do {
                $sn = '/'.$sn unless index($sn, '/') == 0;
                $sn =~ s!/\z!!;
                qr!\A(?:https?://[^/]+)?\Q$sn\E(/[^\?\#]+)!;
        };
+       $env->{REQUEST_URI} =~ $re ? $1 : $env->{PATH_INFO};
 }
 
 sub call {
@@ -68,9 +69,7 @@ sub call {
                $k => $v;
        } split(/[&;]+/, $env->{QUERY_STRING});
 
-       # avoiding $env->{PATH_INFO} here since that's already decoded
-       my ($path_info) = ($env->{REQUEST_URI} =~ path_re($env));
-       $path_info //= $env->{PATH_INFO};
+       my $path_info = path_info_raw($env);
        my $method = $env->{REQUEST_METHOD};
 
        if ($method eq 'POST') {
@@ -300,13 +299,6 @@ sub get_vcs_object ($$$;$) {
        PublicInbox::ViewVCS::show($ctx, $oid, $filename);
 }
 
-sub ctx_get {
-       my ($ctx, $key) = @_;
-       my $val = $ctx->{$key};
-       (defined $val && $val ne '') or die "BUG: bad ctx, $key unusable";
-       $val;
-}
-
 sub need {
        my ($ctx, $extra) = @_;
        my $msg = <<EOF;
@@ -479,6 +471,7 @@ sub cgit {
                        require PublicInbox::Cgit;
                        PublicInbox::Cgit->new($pi_config);
                } else {
+                       require Plack::Util;
                        Plack::Util::inline_object(call => sub { r404() });
                }
        }