From d22396c29856d81e877e17ff4785bcc7474449fb Mon Sep 17 00:00:00 2001 From: Jared Johnson Date: Fri, 7 Nov 2014 16:30:54 -0600 Subject: [PATCH] Add headers with GeoIP data --- plugins/ident/geoip | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/ident/geoip b/plugins/ident/geoip index 58f5d56..5765b5a 100644 --- a/plugins/ident/geoip +++ b/plugins/ident/geoip @@ -130,6 +130,7 @@ sub register { $self->{_args}{db_dir} ||= '/usr/local/share/GeoIP'; $self->load_geoip() or return; + $self->register_hook( data_post => 'add_headers' ); } sub load_geoip { @@ -197,6 +198,17 @@ sub load_geoip2 { return; } +sub add_headers { + my ( $self, $txn ) = @_; + for my $h (qw( Country Country-Name Continent City ASN )) { + my $note = lc "geoip_$h"; + $h =~ s/-/_/; + next if ! $self->connection->notes($note); + $txn->header->delete("X-GeoIP-$h"); + $txn->header->add( "X-GeoIP-$h", $self->connection->notes($note), 0 ); + } +} + sub geoip2_lookup { my $self = shift;