maxmind / mod_maxminddb

MaxMind DB Apache Module
https://maxmind.github.io/mod_maxminddb/
Apache License 2.0
126 stars 28 forks source link

Optionally set notes (IFF `MaxMindDBSetNotes` is `On`) instead of only env #76

Closed mfontani closed 4 years ago

mfontani commented 5 years ago

The old "mod_geoip" used to set both environment and notes. This commit makes the setting of the notes optional.

This enables an Apache mod_perl running with:

<Location "/">
  SetHandler perl-script
  PerlOptions -ParseHeaders -SetupEnv -GlobalRequest
  PerlResponseHandler ...
</Location>

... and with a MaxMind configuration of:

LoadModule maxminddb_module  /usr/lib/apache2/modules/mod_maxminddb.so
<IfModule mod_maxminddb.c>
  # See https://github.com/maxmind/mod_maxminddb
  MaxMindDBEnable On
  MaxMindDBSetNotes On
  MaxMindDBFile COUNTRY_DB /path/to/GeoLite2-Country.mmdb
  MaxMindDBEnv MM_GEOIP_COUNTRY_CODE COUNTRY_DB/country/iso_code
  MaxMindDBEnv MM_GEOIP_CONTINENT_CODE COUNTRY_DB/continent/code
</IfModule>

... to get the client's country code & continent code as an Apache "note", without having to involve the environment.

The reason one usually wants to disable SetupEnv (via "-SetupEnv") for mod_perl handlers is one of performance; from the docs at: https://perl.apache.org/docs/2.0/user/config/config.html#C_SetupEnv_c

But %ENV population is expensive. Those who have moved to the Perl Apache API no longer need this extra %ENV population, and can gain by disabling it.

mfontani commented 5 years ago

Note both commits might want to get squashed prior to merging if you wish to merge both; I'm happy to do so if wanted but am unsure about a nice, proper name for the newly introduced function. I'm happy to rename it to whatever you think would be best; rebase & squash as required.