From 33f9f9f3ffcd47fc12e5b8d61913289ef2d25e3f Mon Sep 17 00:00:00 2001 From: Jean-Frederic Clere Date: Fri, 20 Jul 2007 13:20:30 +0000 Subject: [PATCH] backport of: http://svn.apache.org/viewvc?view=rev&rev=550519 http://svn.apache.org/viewvc?view=rev&rev=551099 http://svn.apache.org/viewvc?view=rev&rev=551126 http://svn.apache.org/viewvc?view=rev&rev=551935 http://svn.apache.org/viewvc?view=rev&rev=554892 Allow to use different values for sessionid in url encoded id and cookies. (PR 41897) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@557993 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ STATUS | 11 ----------- docs/manual/mod/mod_proxy.html.en | 5 ++++- docs/manual/mod/mod_proxy.xml | 5 ++++- modules/proxy/mod_proxy_balancer.c | 24 ++++++++++++++++++------ 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index fc4f0b36c5e..909944f9159 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,9 @@ Changes with Apache 2.2.5 *) mod_cgi, mod_cgid: Fix use of CGI scripts as ErrorDocuments. PR 39710. [Paul Querna, Ruediger Pluem] + *) mod_proxy: Allow to use different values for sessionid + in url encoded id and cookies. PR 41897. [Jean-Frederic Clere] + *) mod_proxy: Fix the 503 returned when session route does not match any of the balancer members. [Mladen Turk] diff --git a/STATUS b/STATUS index ff757f6a820..5ff21b2a3f0 100644 --- a/STATUS +++ b/STATUS @@ -77,17 +77,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * mod_proxy: Allow to use different values for sessionid - in url encoded id and cookies. (PR 41897) - Trunk version of patch: - http://svn.apache.org/viewvc?view=rev&rev=550519 - http://svn.apache.org/viewvc?view=rev&rev=551099 - http://svn.apache.org/viewvc?view=rev&rev=551126 - http://svn.apache.org/viewvc?view=rev&rev=551935 - http://svn.apache.org/viewvc?view=rev&rev=554892 - 2.2.x version of patch: - http://issues.apache.org/bugzilla/attachment.cgi?id=20480 - +1: jfclere, mturk, rpluem PATCHES PROPOSED TO BACKPORT FROM TRUNK: diff --git a/docs/manual/mod/mod_proxy.html.en b/docs/manual/mod/mod_proxy.html.en index 2c16cbc8603..0f96ee460df 100644 --- a/docs/manual/mod/mod_proxy.html.en +++ b/docs/manual/mod/mod_proxy.html.en @@ -891,6 +891,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 @@ -902,7 +905,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 cedd7694348..7d18990a882 100644 --- a/docs/manual/mod/mod_proxy.xml +++ b/docs/manual/mod/mod_proxy.xml @@ -684,6 +684,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 @@ -695,7 +698,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_balancer.c b/modules/proxy/mod_proxy_balancer.c index d02749b1ab3..e2f22235cf6 100644 --- a/modules/proxy/mod_proxy_balancer.c +++ b/modules/proxy/mod_proxy_balancer.c @@ -234,16 +234,27 @@ static proxy_worker *find_route_worker(proxy_balancer *balancer, static proxy_worker *find_session_route(proxy_balancer *balancer, request_rec *r, char **route, + char **sticky_used, char **url) { proxy_worker *worker = NULL; + char *sticky, *sticky_path, *path; if (!balancer->sticky) return NULL; + sticky = sticky_path = apr_pstrdup(r->pool, balancer->sticky); + if ((path = strchr(sticky, '|'))) { + *path++ = '\0'; + sticky_path = path; + } + /* Try to find the sticky route inside url */ - *route = get_path_param(r->pool, *url, balancer->sticky); - if (!*route) - *route = get_cookie_param(r, balancer->sticky); + *sticky_used = sticky_path; + *route = get_path_param(r->pool, *url, sticky_path); + if (!*route) { + *route = get_cookie_param(r, sticky); + *sticky_used = sticky; + } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "proxy: BALANCER: Found value %s for " "stickysession %s", *route, balancer->sticky); @@ -369,6 +380,7 @@ static int proxy_balancer_pre_request(proxy_worker **worker, int access_status; proxy_worker *runtime; char *route = NULL; + char *sticky = NULL; apr_status_t rv; *worker = NULL; @@ -383,7 +395,7 @@ static int proxy_balancer_pre_request(proxy_worker **worker, /* Step 2: find the session route */ - runtime = find_session_route(*balancer, r, &route, url); + runtime = find_session_route(*balancer, r, &route, &sticky, url); /* Lock the LoadBalancer * XXX: perhaps we need the process lock here */ @@ -493,12 +505,12 @@ static int proxy_balancer_pre_request(proxy_worker **worker, access_status = rewrite_url(r, *worker, url); /* Add the session route to request notes if present */ if (route) { - apr_table_setn(r->notes, "session-sticky", (*balancer)->sticky); + apr_table_setn(r->notes, "session-sticky", sticky); apr_table_setn(r->notes, "session-route", route); /* Add session info to env. */ apr_table_setn(r->subprocess_env, - "BALANCER_SESSION_STICKY", (*balancer)->sticky); + "BALANCER_SESSION_STICKY", sticky); apr_table_setn(r->subprocess_env, "BALANCER_SESSION_ROUTE", route); } -- 2.47.3