Ticket #1546 (new enhancement)

Opened 5 months ago

Last modified 4 months ago

Enhancements for mod_geoip

Reported by: spillgroup Assigned to: jan
Priority: normal Milestone: 1.4.20
Component: core Version: 1.4.18
Severity: normal Keywords:
Cc: Blocking:
Need Feedback: 0

Description

I'm adding several patches for use with mod_geoip (http://trac.lighttpd.net/trac/wiki/Docs:ModGeoip) which allow:

* A 'geoip.default_country_code' to be set when no matching country could be found.

* A 'geoip.force_lowercase' to be set to force all returned country codes in lowercase.

* Environment variables to be picked up and used in mod_redirect targets.

Example of combined usage:

geoip.db-filename              = "/usr/share/GeoIP/GeoIP.dat"
geoip.memory-cache             = "enable"

$HTTP["host"] =~ "^(www\.example\.com)(:[0-9]+)?$" {
        geoip.default_country_code = "us"
        geoip.force_lowercase = "enable"
        url.redirect = (
                "^/$"           => "http://%1%2/#GEOIP_COUNTRY_CODE#/",
        )
}

This allows us to do in-server redirects based on GeoIP country codes. I know the patches aren't ideal (changes only done for country codes for example), but they might be useful to someone nevertheless. It beats using a PHP script, but some LUA might also do the trick. These patches are quite old, but have been in large scale production for over a year now without problems.

Attachments

lighttpd-1.4.11-mod_geoip_default_country_code.patch (2.9 kB) - added by spillgroup on 01/31/2008 10:07:21 AM.
lighttpd-1.4.13-mod_geoip_lowercase.patch (5.9 kB) - added by spillgroup on 01/31/2008 10:07:47 AM.
lighttpd-1.4.13-mod_geoip_redirect.patch (1.9 kB) - added by spillgroup on 01/31/2008 10:08:15 AM.

Change History

01/31/2008 10:07:21 AM changed by spillgroup

  • attachment lighttpd-1.4.11-mod_geoip_default_country_code.patch added.

01/31/2008 10:07:47 AM changed by spillgroup

  • attachment lighttpd-1.4.13-mod_geoip_lowercase.patch added.

01/31/2008 10:08:15 AM changed by spillgroup

  • attachment lighttpd-1.4.13-mod_geoip_redirect.patch added.

01/31/2008 10:47:00 AM changed by stbuehler

lighttpd-1.4.13... is a "little bit" old ;-)

  1. I think your patch split is not good - there are default_country parts in lowercase.patch.
    OTOH, I think both patches are good, so perhaps you don't need to split them.
  2. I don't think the redirect patch should be used - mod_magnet ;-)
  3. Why do you use snprintf with a const limit if you know the size of the buffer and the string?
  4. buffer_reset(x) shouldn't be necessary before a buffer_copy_*(x, *)
  5. Can you explain why you disabled mod_geoip_subrequest for p->handle_subrequest_start ?
  6. I think if (buffer_is_equal_string(du->key, CONST_STR_LEN("geoip.default_country_code"))) { could be else if (buffer_is_equal_string(du->key, CONST_STR_LEN("geoip.default_country_code"))) {

BTW: Does anyone know why the mod is not upstream? Does it contain blocking io-code?

03/07/2008 09:01:50 AM changed by spillgroup

This was one of the first changes done by our (external) development team to the Lightty code. Sorry if the quality is not that good. Regarding the use of mod_magnet instead of mod_redirect: wouldn't that impose a lot more overhead?


Add/Change #1546 (Enhancements for mod_geoip)




Change Properties