mod_proxy_balancer.c revision 813df5e678b2fc138a1c6cfeea19a5ed4cd51b4e
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * applicable.
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * Licensed under the Apache License, Version 2.0 (the "License");
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * you may not use this file except in compliance with the License.
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * You may obtain a copy of the License at
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * Unless required by applicable law or agreed to in writing, software
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * distributed under the License is distributed on an "AS IS" BASIS,
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * See the License for the specific language governing permissions and
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * limitations under the License.
8510ec2d1034d77b800ff605a9651e513bcef4a2fuankg/* Load balancer module for Apache proxy */
e39eb98e3ad3fbf5c34b2fa1d16861f95143e22esfstatic int proxy_balancer_canon(request_rec *r, char *url)
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf const char *err;
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf /* do syntatic check.
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * We break the URL into host, port, path, search
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf "error parsing URL %s: %s",
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf /* now parse path/search args, according to rfc1738 */
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf /* N.B. if this isn't a true proxy request, then the URL _path_
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * has already been decoded. True proxy requests have r->uri
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * == r->unparsed_uri, and no others have that property.
e39eb98e3ad3fbf5c34b2fa1d16861f95143e22esf /* process path */
e39eb98e3ad3fbf5c34b2fa1d16861f95143e22esf path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0, r->proxyreq);
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf r->filename = apr_pstrcat(r->pool, "proxy:balancer://", host,
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf "/", path, (search) ? "?" : "", (search) ? search : "", NULL);
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sfstatic int init_balancer_members(proxy_server_conf *conf, server_rec *s,
83bad90d62e8f0283585ba0d3c7ac29b6070ea6csf /* Set to the original configuration */
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf /* Set default number of attempts to the number of
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * workers.
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf if (!balancer->max_attempts_set && balancer->workers->nelts > 1) {
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf/* Retrieve the parameter with the given name
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * Something like 'JSESSIONID=12345...N'
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf const char *name)
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf for (path = strstr(url, name); path; path = strstr(path + 1, name)) {
d6fc66efa723db8b3ee5e9fd32579bed884e4e58sf * Session path was found, get it's value
return path;
return NULL;
const char *cookies;
const char *start_cookie;
++start_cookie;
++start_cookie;
return cookie;
return NULL;
const char *route)
return worker;
worker++;
return NULL;
request_rec *r,
char **route,
char **url)
return NULL;
if (!*route)
if (*route) {
return worker;
return NULL;
request_rec *r)
int total_factor = 0;
worker++;
if (mycandidate) {
return mycandidate;
request_rec *r)
worker++;
if (mycandidate) {
return mycandidate;
request_rec *r)
return NULL;
#if APR_HAS_THREADS
return candidate;
char **url)
if (scheme)
if (!worker) {
NULL));
return OK;
request_rec *r,
int access_status;
if (!*balancer &&
return DECLINED;
return DECLINED;
if (runtime) {
int i, total_factor = 0;
workers++;
return HTTP_SERVICE_UNAVAILABLE;
if (!*worker) {
if (!runtime) {
return HTTP_SERVICE_UNAVAILABLE;
if (route) {
return access_status;
request_rec *r,
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
int access_status;
const char *name;
return DECLINED;
return DECLINED;
if (r->args) {
return access_status;
return HTTP_BAD_REQUEST;
if (sc) {
if (ws) {
++worker;
if (bsel) {
const char *val;
if (ival >= 0)
if (ival >= 0)
ent++;
if (wsel) {
const char *val;
if (bsel)
++worker;
++balancer;
++worker;
++balancer;
else if (bsel) {
ent++;
return OK;
balancer++;
s = s->next;
return OK;