#710477 libapache2-mod-perl2: API changes with httpd24 transition: remote_ip and remote_port

Package:
libapache2-mod-perl2
Source:
libapache2-mod-perl2
Description:
Integration of perl with the Apache2 web server
Submitter:
Niko Tyni
Date:
2019-12-02 02:57:09 UTC
Severity:
normal
#710477#5
Date:
2013-05-31 07:26:47 UTC
From:
To:
From #666822:

Filing a bug so we don't forget this.

#710477#10
Date:
2019-11-28 14:02:52 UTC
From:
To:
client_ip and remote_ip do not work. Is there no way to get this value
anymore?

Can't locate object method "remote_ip" via package "Apache2::Connection"
Can't locate object method "client_ip" via package "Apache2::Connection"
*Apache/2.4.29 (Ubuntu) OpenSSL/1.1.1 mod_apreq2-20090110/2.8.0
mod_perl/2.0.10 Perl/v5.26.1*

#710477#13
Date:
2019-11-28 20:44:26 UTC
From:
To:
-=| Chris Denley, 28.11.2019 08:02:52 -0600 |=-

the following works for me:

    my $conn = $r->connection;

    my $ip_addr
        = $conn->can('client_ip')
        ? $conn->client_ip
        : $conn->remote_ip;

so one of them works, and I bet it is 'client_ip'

(Debian/sid and Debian/buster (and several releases before that))

Can you share the code that fails for you?

#710477#18
Date:
2019-12-02 02:53:00 UTC
From:
To:
Putting a simple test script together, I found my problem. The client_ip
method doesn't work on Apache2::Connection objects unless the
Apache2::Connection module is loaded in the current namespace.

package test;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::Const -compile => 'OK';

sub handler {
   my $r = shift;
   $r->content_type('text/plain');
   my $ref = ref($r);
   print "ref(\$r) = $ref\n";
   my $conn = $r->connection;
   $ref = ref($conn);
   print "ref(\$conn) = $ref\n";
   for(1..2) {
      if($_==2) {
         print "require Apache2::Connection\n";
         require Apache2::Connection;
      }
      if($conn->can('client_ip')) {
         print "client_ip: ".$conn->client_ip."\n";
      }
      else {
         print "\$conn cannot client_ip\n";
      }
      if($conn->can('remote_ip')) {
         print "remote_ip: ".$conn->remote_ip."\n";
      }
      else {
         print "\$conn cannot remote_ip\n";
      }
   }
   return Apache2::Const::OK;
}
1;

ref($r) = Apache2::RequestRec
ref($conn) = Apache2::Connection
$conn cannot client_ip
$conn cannot remote_ip
require Apache2::Connection
client_ip: 127.0.0.1
$conn cannot remote_ip
anymore?
mod_perl/2.0.10