]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
http: don't store `127.0.0.1' for idle clients
authorEric Wong <e@80x24.org>
Thu, 20 Jun 2024 22:54:34 +0000 (22:54 +0000)
committerEric Wong <e@80x24.org>
Tue, 25 Jun 2024 17:03:25 +0000 (17:03 +0000)
For persistent HTTP clients, we can set REMOTE_ADDR lazily
for the common `127.0.0.1' value and save a few bytes when
dealing with idle connections which linger inbetween requests.

lib/PublicInbox/HTTP.pm

index 73632aee2af0ebf64ed9e7573e3b9cb0b0f867a6..bead222ec3fb5a159b34f6094ff4a01b090836d5 100644 (file)
@@ -70,8 +70,9 @@ sub new ($$$) {
                $wbuf = [ \&PublicInbox::DS::accept_tls_step ];
        }
        $self->{wbuf} = $wbuf if $wbuf;
-       ($self->{remote_addr}, $self->{remote_port}) =
+       ($addr, $self->{remote_port}) =
                PublicInbox::Daemon::host_with_port($addr);
+       $self->{remote_addr} = $addr if $addr ne '127.0.0.1';
        $self->SUPER::new($sock, $ev | EPOLLONESHOT);
 }
 
@@ -140,7 +141,7 @@ sub app_dispatch {
        $self->rbuf_idle($rbuf);
        my $env = $self->{env};
        $self->{env} = undef; # for exists() check in ->busy
-       $env->{REMOTE_ADDR} = $self->{remote_addr};
+       $env->{REMOTE_ADDR} = $self->{remote_addr} // '127.0.0.1';
        $env->{REMOTE_PORT} = $self->{remote_port};
        if (defined(my $host = $env->{HTTP_HOST})) {
                $host =~ s/:([0-9]+)\z// and $env->{SERVER_PORT} = $1 + 0;