Author: jfrederic.clere(a)jboss.com
Date: 2009-02-10 09:37:12 -0500 (Tue, 10 Feb 2009)
New Revision: 2272
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Fix for MODCLUSTER-44.
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2009-02-10 12:22:33 UTC
(rev 2271)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2009-02-10 14:37:12 UTC
(rev 2272)
@@ -687,12 +687,23 @@
return NULL;
}
-static char *get_cookie_param(request_rec *r, const char *name)
+/*
+ * Read the cookie corresponding to name
+ * @param r request.
+ * @param name name of the cookie
+ * @param in tells if cookie should read from the request or the response
+ * @return the value of the cookie
+ */
+static char *get_cookie_param(request_rec *r, const char *name, int in)
{
const char *cookies;
const char *start_cookie;
- if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
+ if (in)
+ cookies = apr_table_get(r->headers_in, "Cookie");
+ else
+ cookies = apr_table_get(r->headers_out, "Set-Cookie");
+ if (cookies) {
for (start_cookie = ap_strstr_c(cookies, name); start_cookie;
start_cookie = ap_strstr_c(start_cookie + 1, name)) {
if (start_cookie == cookies ||
@@ -744,7 +755,7 @@
*sticky_used = sticky_path;
route = get_path_param(r->pool, uri , sticky_path);
if (!route) {
- route = get_cookie_param(r, sticky);
+ route = get_cookie_param(r, sticky, 1);
*sticky_used = sticky;
}
return route;
@@ -1981,6 +1992,9 @@
proxy_cluster_helper *helper;
const char *sessionid;
const char *route;
+ char *cookie = NULL;
+ const char *sticky;
+ char *oroute;
if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,
@@ -2004,8 +2018,32 @@
worker->s->busy--;
/* Add information about sessions corresponding to a node */
+ sticky = apr_table_get(r->notes, "session-sticky");
+ if (sticky == NULL) {
+ char *path, *stick;
+ stick = apr_pstrdup(r->pool, balancer->sticky);
+ if ((path = strchr(stick, '|'))) {
+ *path++ = '\0';
+ }
+ sticky = (const char *) stick;
+ }
+ cookie = get_cookie_param(r, sticky, 0);
sessionid = apr_table_get(r->notes, "session-id");
route = apr_table_get(r->notes, "session-route");
+ if (cookie) {
+ if (sessionid && strcmp(cookie, sessionid)) {
+ /* The cookie has changed, remove the old one and store the next one */
+ sessionidinfo_t ou;
+ strncpy(ou.sessionid, sessionid, SESSIONIDSZ);
+ ou.id = 0;
+ sessionid_storage->remove_sessionid(&ou);
+ }
+ if ((oroute = strchr(cookie, '.')) != NULL )
+ oroute++;
+ route = oroute;
+ sessionid = cookie;
+ }
+
if (sessionid && route) {
sessionidinfo_t ou;
strncpy(ou.sessionid, sessionid, SESSIONIDSZ);
Show replies by date