]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
http: expose reused connection counter in PSGI env
authorEric Wong <e@80x24.org>
Sun, 13 Jul 2025 00:08:34 +0000 (00:08 +0000)
committerEric Wong <e@80x24.org>
Wed, 16 Jul 2025 09:20:34 +0000 (09:20 +0000)
`$env->{pi-httpd.request_nr}' is now accessible via the PSGI
env for middlewares to use to identify reused connections.
This can be useful for middlewares to implement rules for
identifying and rejecting/allowing certain clients (e.g.
aggressive bots).

lib/PublicInbox/HTTP.pm

index 83f2c6a24dccd8916a5d95a25de0e0d87c1d2ae4..3cb3b35fb81c3a34d5b65584577868dd279435e7 100644 (file)
@@ -144,6 +144,7 @@ sub app_dispatch {
        my ($self, $input, $rbuf) = @_;
        $self->rbuf_idle($rbuf);
        my $env = $self->{env};
+       $env->{'pi-httpd.request_nr'} = $self->{request_nr}++;
        $self->{env} = undef; # for exists() check in ->busy
        $env->{REMOTE_ADDR} = $self->{remote_addr} // '127.0.0.1';
        $env->{REMOTE_PORT} = $self->{remote_port};