commit 61848d9db46191fb576d9ff0af196c3a771fe0a1
Author: Thomas Eckert <Thomas.Eckert@Sophos.com>
Date:   Tue Apr 2 14:46:31 2013 +0200

    Make directive understand balancer names as argument
    
    Directive: ProxyPassReverseCookieDomain

diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
index 5ab5d91..d2a35dc 100644
--- a/modules/proxy/proxy_util.c
+++ b/modules/proxy/proxy_util.c
@@ -933,6 +933,35 @@ PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r,
     return url;
 }
 
+/* Attempts to translate 'balancer_name' to a valid balancer, using the 'domain_name'
+ * to find the worker which matches to the domain. */
+PROXY_DECLARE(int) ap_proxy_balancer_matches_domain(request_rec *r, const char* domain_name, const char *balancer_name)
+{
+  if (ap_proxy_valid_balancer_name((char *)balancer_name, 0) == 0)
+    return 0;
+
+  proxy_server_conf *sconf = (proxy_server_conf *) ap_get_module_config(r->server->module_config, &proxy_module);
+  proxy_balancer *balancer = ap_proxy_get_balancer(r->pool, sconf, balancer_name, 1);
+  if (balancer == NULL)
+    return 0;
+
+  int n;
+  proxy_worker **worker = (proxy_worker **)balancer->workers->elts;
+  for (n = 0; n < balancer->workers->nelts; n++) {
+    char *balancer_name = (*worker)->s->name;
+
+    char *balancer_name_scheme_start = strstr(balancer_name, "://");
+    char *domain_name_scheme_start = strstr(domain_name, "://");
+    if ((balancer_name_scheme_start != NULL) && (domain_name_scheme_start == NULL))
+      balancer_name = balancer_name_scheme_start + 3;
+
+    if (strcasecmp(balancer_name, domain_name) == 0)
+      return 1;
+  }
+
+  return 0;
+}
+
 /*
  * Cookies are a bit trickier to match: we've got two substrings to worry
  * about, and we can't just find them with strstr 'cos of case.  Regexp
@@ -1003,7 +1032,8 @@ PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r,
         }
         for (i = 0; i < conf->cookie_domains->nelts; i++) {
             l2 = strlen(ent[i].fake);
-            if (l1 >= l2 && strncasecmp(ent[i].fake, domainp, l2) == 0) {
+            if ((ap_proxy_balancer_matches_domain(r, domainp, ent[i].fake) == 1) ||
+                (l1 >= l2 && strncasecmp(ent[i].fake, domainp, l2) == 0)) {
                 newdomain = ent[i].real;
                 ddiff = strlen(newdomain) - l1;
                 break;
