Author: jfrederic.clere(a)jboss.com
Date: 2008-10-22 14:02:16 -0400 (Wed, 22 Oct 2008)
New Revision: 1987
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Add get_route and remove duplicate code.
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-10-22 16:49:00 UTC
(rev 1986)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-10-22 18:02:16 UTC
(rev 1987)
@@ -565,6 +565,34 @@
}
/**
+ * Check that the request has a sessionid with a route
+ * @param r the request_rec.
+ * @param stickyval the cookie or/and parameter name.
+ * @param uri part of the URL to for the session parameter.
+ * @param sticky_used the string that was used to find the route
+ */
+static char *get_route(request_rec *r, const char *stickyval, char *uri, char
**sticky_used)
+{
+ char *sticky, *sticky_path;
+ char *path;
+ char *route;
+
+ /* for 2.2.x the sticky parameter may contain 2 values */
+ sticky = sticky_path = apr_pstrdup(r->pool, stickyval);
+ if ((path = strchr(sticky, '|'))) {
+ *path++ = '\0';
+ sticky_path = path;
+ }
+ *sticky_used = sticky_path;
+ route = get_path_param(r->pool, uri , sticky_path);
+ if (!route) {
+ route = get_cookie_param(r, sticky);
+ *sticky_used = sticky;
+ }
+ return route;
+}
+
+/**
* Check that the request has a sessionid (even invalid)
* @param r the request_rec.
* @param balancer_name name of the balancer. (to find the balancer)
@@ -577,7 +605,7 @@
proxy_balancer *balancer = balance;
char *route;
char *uri = r->filename + 6;
- char *sticky_path, *sticky, *path;
+ char *sticky_used;
int i;
if (balancer == NULL) {
@@ -597,15 +625,7 @@
if (balancer->sticky == NULL)
return 0;
- /* for 2.2.x the sticky parameter may contain 2 values */
- sticky = sticky_path = apr_pstrdup(r->pool, balancer->sticky);
- if ((path = strchr(sticky, '|'))) {
- *path++ = '\0';
- sticky_path = path;
- }
- route = get_path_param(r->pool, uri , sticky_path);
- if (route == NULL)
- route = get_cookie_param(r, sticky);
+ route = get_route(r, balancer->sticky, uri, &sticky_used);
if (route) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"mod_proxy_cluster: found route %s", route);
@@ -1353,22 +1373,13 @@
if (! (balancer->sticky_force & STSESSION))
return NULL;
- sticky = sticky_path = apr_pstrdup(r->pool, balancer->sticky);
- if ((path = strchr(sticky, '|'))) {
- *path++ = '\0';
- sticky_path = path;
+ *route = get_route(r, balancer->sticky, *url, sticky_used);
+ if (*route) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "proxy: CLUSTER: Found value %s for "
+ "stickysession %s", *route, balancer->sticky);
}
-
- /* Try to find the sticky route inside url */
- *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: CLUSTER: 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.