]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
wwwstream: shorten cloneurl uniquification
[public-inbox.git] / lib / PublicInbox / WWW.pm
index 251979d5db6ee88af2defb614f2eed43ea5edb6e..efe7c8ca0064427e3425bb99190e41c373837a94 100644 (file)
@@ -22,6 +22,7 @@ use PublicInbox::MID qw(mid_escape);
 require PublicInbox::Git;
 use PublicInbox::GitHTTPBackend;
 use PublicInbox::UserContent;
+use PublicInbox::WwwStatic qw(r path_info_raw);
 
 # TODO: consider a routing tree now that we have more endpoints:
 our $INBOX_RE = qr!\A/([\w\-][\w\.\-]*)!;
@@ -42,17 +43,6 @@ sub run {
        PublicInbox::WWW->new->call($req->env);
 }
 
-my %path_re_cache;
-
-sub path_re ($) {
-       my $sn = $_[0]->{SCRIPT_NAME};
-       $path_re_cache{$sn} ||= do {
-               $sn = '/'.$sn unless index($sn, '/') == 0;
-               $sn =~ s!/\z!!;
-               qr!\A(?:https?://[^/]+)?\Q$sn\E(/[^\?\#]+)!;
-       };
-}
-
 sub call {
        my ($self, $env) = @_;
        my $ctx = { env => $env, www => $self };
@@ -67,9 +57,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') {
@@ -83,7 +71,7 @@ sub call {
                }
        }
        elsif ($method !~ /\AGET|HEAD\z/) {
-               return r(405, 'Method Not Allowed');
+               return r(405);
        }
 
        # top-level indices and feeds
@@ -176,12 +164,9 @@ sub r404 {
                require PublicInbox::ExtMsg;
                return PublicInbox::ExtMsg::ext_msg($ctx);
        }
-       r(404, 'Not Found');
+       r(404);
 }
 
-# simple response for errors
-sub r { [ $_[0], ['Content-Type' => 'text/plain'], [ join(' ', @_, "\n") ] ] }
-
 sub news_cgit_fallback ($) {
        my ($ctx) = @_;
        my $www = $ctx->{www};