[squid-users] Re: accelerator mode in case where content depends on client IP address

From: Chris Lightfoot <chris@dont-contact.us>
Date: Thu, 8 Jun 2006 14:51:51 +0100

On Tue, May 30, 2006 at 05:00:02PM +0100, Chris Lightfoot wrote:
> I am looking at deploying squid as an HTTP accelerator in
> front of a site which uses an IP-to-country lookup to vary
> certain elements of the site's content. Obviously I can't
> specify this information in the Vary: header; I could have
> the site emit `Vary: *' but that would guarantee that no
> useful cacheing is done.
>
> Is there a suggested solution to this? One which occurs to
> me is to modify squid to do the IP-to-country lookup
> itself, and to add an additional header to the client's
> request containing the results of the lookup; the
> application behind the accelerator could then name this
> header in the Vary: header it returns. I think that would
> work, but it's a bit ugly; is there a better (or, better
> still, standard) approach?

for those who are interested, this is the approach I
adopted in the end. The patch for squid-2.5.9 (as in
Debian stable, which is the platform we're using) is
below, in case this is of use to others. There are also
binary and source packages on http://debian.mysociety.org/
with this modification. So far it's working well.

--- squid-2.5.9-orig/configure.in 2005-02-23 23:54:54.000000000 +0000
+++ squid-2.5.9/configure.in 2006-06-02 19:00:59.000000000 +0100
@@ -775,6 +775,20 @@
   fi
 ])
 
+AC_ARG_ENABLE(geoip-lookups,
+[ --enable-geoip-lookups
+ This adds code which does GeoIP lookups on each
+ incoming connection, and synthesises an
+ X-GeoIP-Country: header on each client connection.],
+[ if test "$enableval" = "yes" ; then
+ echo "Enabling GeoIP Lookups"
+ AC_DEFINE(USE_GEOIP, 1)
+ USE_GEOIP="yes"
+ else
+ AC_DEFINE(USE_GEOIP, 0)
+ fi
+])
+
 AM_CONDITIONAL(USE_DNSSERVER, false)
 use_dnsserver=
 AC_ARG_ENABLE(internal-dns,
@@ -1893,6 +1907,19 @@
     sleep 10
 fi
 
+dnl If we're configured to use GeoIP then we need to find the appropriate
+dnl header files and library
+if test "$USE_GEOIP" ; then
+ AC_CHECK_LIB(GeoIP, GeoIP_new)
+ AC_CHECK_HEADERS(GeoIP.h)
+ if test "$ac_cv_header_GeoIP_h" = "yes" ; then
+ echo "using GeoIP"
+ else
+ echo "ERROR: GeoIP not found"
+ exit 1
+ fi
+fi
+
 if test -z "$USE_GNUREGEX" ; then
     case "$host" in
     *-sun-solaris2.[[0-4]])
--- squid-2.5.9-orig/src/client_side.c 2005-02-20 19:07:45.000000000 +0000
+++ squid-2.5.9/src/client_side.c 2006-06-02 19:51:24.000000000 +0100
@@ -3104,6 +3104,12 @@
                safe_free(prefix);
                break;
            }
+#if USE_GEOIP
+ /* Cull any existing country header and add a new one. */
+ httpHeaderDelByName(&request->header, "X-GeoIP-Country");
+ httpHeaderPutExt(&request->header, "X-GeoIP-Country",
+ *conn->country ? conn->country : "none");
+#endif
            request->flags.accelerated = http->flags.accel;
            if (!http->flags.internal) {
                if (internalCheck(strBuf(request->urlpath))) {
--- squid-2.5.9-orig/src/structs.h 2005-02-23 00:06:35.000000000 +0000
+++ squid-2.5.9/src/structs.h 2006-06-02 15:28:30.000000000 +0100
@@ -1138,6 +1138,9 @@
        int n;
        time_t until;
     } defer;
+
+ /* country inferred from peer IP address */
+ char country[3];
 };
 
 struct _ipcache_addrs {

-- 
Television is a medium, so called
because it is neither rare nor well done.
Received on Thu Jun 08 2006 - 07:51:55 MDT

This archive was generated by hypermail pre-2.1.9 : Sat Jul 01 2006 - 12:00:01 MDT