Fixed crash on retrieving the remote IP for: &a_href_cz
[MyWeb.git] / Web.pm
diff --git a/Web.pm b/Web.pm
index 386f769..5c2dd07 100644 (file)
--- a/Web.pm
+++ b/Web.pm
@@ -104,7 +104,7 @@ use Carp qw(cluck confess);
 use URI::Escape;
 require HTTP::BrowserDetect;
 require HTTP::Negotiate;
-my $have_Geo_IP; BEGIN { $have_Geo_IP=eval { require Geo::IP; 1; }; }
+our $have_Geo_IP; BEGIN { $have_Geo_IP=eval { require Geo::IP; 1; }; }
 # Do not: use ModPerl::Util qw(exit);
 # to prevent in mod_perl2: "exit" is not exported by the ModPerl::Util module
 # I do not know why.
@@ -121,6 +121,7 @@ require Data::Compare;
 use Data::Dumper;
 require Encode;
 use Apache2::Filter;
+use Apache2::Connection;
 
 
 #our $W;
@@ -237,7 +238,7 @@ my($class,%args)=@_;
        $W->{"headers_in"}=My::Hash::Merge->new(
                        $W->{"headers_in"},
                        My::Hash::Sub->new({
-                               "_get_remote_host"=>sub { return $W->{"r"}->get_remote_host(); },
+                               "_remote_ip"=>sub { return $W->{"r"}->connection()->remote_ip(); },
                                }),
                        );
        $W->{"headers_in"}=My::Hash::Readonly->new($W->{"headers_in"});
@@ -671,7 +672,7 @@ sub remote_ip ()
        # As 'Apache2::ForwardedFor' takes the first of $ENV{"HTTP_X_FORWARDED_FOR"}
        # while the contents is '127.0.0.1, 213.220.195.171' if client has its own proxy.
        # We must take the last item ourselves.
-       my $r=$W->{"headers_in"}{"X-Forwarded-For"} || $W->{"headers_in"}{"_get_remote_host"};
+       my $r=$W->{"headers_in"}{"X-Forwarded-For"} || $W->{"headers_in"}{"_remote_ip"};
        $r=~s/^.*,\s*//;
        return $r;
 }