I'm trying to make ProxyPassReverseCookieDomain understand two things it
apparently does not understand at the moment: accept 1) balancer names and
2) variables as arguments. For the first problem I was able to come up with
a patch based on the code for the ProxyPassReverse directive (see below).
The second problem gives me headaches though. Suppose I would like to do
ProxyPassReverseCookieDomain balancer://foobar/ %{HTTP_HOST}
so the %{HTTP_HOST} expression is translated to the http host field of the
original client request. This is required in case the reverse proxy is
reachable through multiple domains because the cookie must be set to the
correct domain - else it will not be transmitted by the client's agent in
the future.To achieve this I would have to carry this information from the
client->proxy request to the proxy->server request and their responses.
Obviously, this 'linking' of requests is already done be mod_proxy since it
could not function as a reveres proxy otherwise.
I would be grateful for some hints on this.
My preliminary patch for the balancer issue is located below
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
index 5ab5d91..5345246 100644
--- a/modules/proxy/proxy_util.c
+++ b/modules/proxy/proxy_util.c
@@ -933,6 +933,29 @@ 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)
+{
+ proxy_server_conf *sconf = (proxy_server_conf *)
ap_get_module_config(r->server->module_config, &proxy_module);
+
+ if (ap_proxy_valid_balancer_name((char *)balancer_name, 0) == 0)
+ return 0;
+
+ 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++) {
+ if (strcasecmp((*worker)->s->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 +1026,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;