From: Eric Wong Date: Thu, 20 Jun 2024 22:54:34 +0000 (+0000) Subject: http: don't store `127.0.0.1' for idle clients X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22bf858a5ac917188ce36feea5a4d51372f61dc6;p=thirdparty%2Fpublic-inbox.git http: don't store `127.0.0.1' for idle clients 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. --- diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 73632aee2..bead222ec 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -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;