From: Jean-Frederic Clere Date: Mon, 25 Jun 2007 14:42:25 +0000 (+0000) Subject: Add sticky_path to solve PR41897. X-Git-Tag: 2.3.0~1757 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4dee811cb9c19c29a79fc7f5a95aac6504417f1b;p=thirdparty%2Fapache%2Fhttpd.git Add sticky_path to solve PR41897. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@550519 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/mod_proxy.html.en b/docs/manual/mod/mod_proxy.html.en index bc31ca60af1..1cec55bc792 100644 --- a/docs/manual/mod/mod_proxy.html.en +++ b/docs/manual/mod/mod_proxy.html.en @@ -899,6 +899,9 @@ through Balancer sticky session name. The value is usually set to something like JSESSIONID or PHPSESSIONID, and it depends on the backend application server that support sessions. + If the backend application server uses different name for cookies + and url encoded id (like servlet containers) use | to to separate them. + The first part is for the cookie the second for the path. timeout 0 @@ -910,7 +913,7 @@ through

A sample balancer setup

ProxyPass /special-area http://special.example.com/ smax=5 max=10
- ProxyPass / balancer://mycluster/ stickysession=jsessionid nofailover=On
+ ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid nofailover=On
<Proxy balancer://mycluster>
BalancerMember http://1.2.3.4:8009
diff --git a/docs/manual/mod/mod_proxy.xml b/docs/manual/mod/mod_proxy.xml index 55e2b7f79b6..3a0cce2a8dd 100644 --- a/docs/manual/mod/mod_proxy.xml +++ b/docs/manual/mod/mod_proxy.xml @@ -709,6 +709,9 @@ expressions Balancer sticky session name. The value is usually set to something like JSESSIONID or PHPSESSIONID, and it depends on the backend application server that support sessions. + If the backend application server uses different name for cookies + and url encoded id (like servlet containers) use | to to separate them. + The first part is for the cookie the second for the path. timeout 0 @@ -720,7 +723,7 @@ expressions

A sample balancer setup

ProxyPass /special-area http://special.example.com/ smax=5 max=10
- ProxyPass / balancer://mycluster/ stickysession=jsessionid nofailover=On
+ ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid nofailover=On
<Proxy balancer://mycluster>
BalancerMember http://1.2.3.4:8009
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index cf25829a5eb..07110200a75 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -275,11 +275,16 @@ static const char *set_balancer_param(proxy_server_conf *conf, int ival; if (!strcasecmp(key, "stickysession")) { + char *path; /* Balancer sticky session name. * Set to something like JSESSIONID or * PHPSESSIONID, etc.., */ - balancer->sticky = apr_pstrdup(p, val); + balancer->sticky = balancer->sticky_path = apr_pstrdup(p, val); + if ((path = strchr(balancer->sticky, '|'))) { + *path++ = '\0'; + balancer->sticky_path = path; + } } else if (!strcasecmp(key, "nofailover")) { /* If set to 'on' the session will break diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index a8e8a260aef..a6a8ecc30b3 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -365,6 +365,7 @@ struct proxy_balancer { apr_thread_mutex_t *mutex; /* Thread lock for updating lb params */ #endif void *context; /* general purpose storage */ + const char *sticky_path; /* URL sticky session identifier */ }; struct proxy_balancer_method { diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c index c82e24aecbd..c3f9605c6a0 100644 --- a/modules/proxy/mod_proxy_balancer.c +++ b/modules/proxy/mod_proxy_balancer.c @@ -248,12 +248,19 @@ static proxy_worker *find_session_route(proxy_balancer *balancer, if (!balancer->sticky) return NULL; /* Try to find the sticky route inside url */ - *route = get_path_param(r->pool, *url, balancer->sticky); - if (!*route) + *route = get_path_param(r->pool, *url, balancer->sticky_path); + if (*route) { + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "proxy: BALANCER: Found value %s for " + "stickysession %s", *route, balancer->sticky_path); + } + else { *route = get_cookie_param(r, balancer->sticky); - ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, - "proxy: BALANCER: Found value %s for " - "stickysession %s", *route, balancer->sticky); + if (*route) + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "proxy: BALANCER: Found value %s for " + "stickysession %s", *route, balancer->sticky); + } /* * If we found a value for sticksession, find the first '.' within. * Everything after '.' (if present) is our route.