]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
reject_bots: delay app call
authorEric Wong <e@80x24.org>
Tue, 2 Sep 2025 20:30:12 +0000 (20:30 +0000)
committerEric Wong <e@80x24.org>
Sat, 6 Sep 2025 18:36:07 +0000 (18:36 +0000)
We can save some cycles by delaying the potentially expensive
app invocation until after the PATH_INFO + user-agent check.

contrib/RejectBots.pm

index 28561fa790b4ab450ead763a90a9768f2ef86a8f..fdfd41a53aea34e1a7e0434a2a5eb3e1c692d70c 100644 (file)
@@ -22,7 +22,6 @@ sub call {
        my ($self, $env) = @_;
        my $ua = $env->{HTTP_USER_AGENT} // '';
        return [ 403, [], [] ] if $ua =~ /$bad_ua/o;
-       my $res = $self->app->($env);
        my $uri;
        if ($env->{PATH_INFO} !~ /\.css\z/ &&
                        $ua =~ m!\A(?:Mozilla|Opera)/! &&
@@ -35,7 +34,7 @@ EOM
                [ 200, [ 'Refresh' => 1,
                        'Content-Length' => length($body) ], [ $body ] ]
        } else {
-               $res;
+               $self->app->($env);
        }
 }