mod_proxy.c revision b6832863054a2d09233ce92945e0faceb932a620
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* Copyright 1999-2004 The Apache Software Foundation
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Licensed under the Apache License, Version 2.0 (the "License");
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * you may not use this file except in compliance with the License.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * You may obtain a copy of the License at
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Unless required by applicable law or agreed to in writing, software
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * distributed under the License is distributed on an "AS IS" BASIS,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndAPR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
fac8c35bfb158112226ab43ddf84d59daca5dc30ndAPR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem#define MAX(x,y) ((x) >= (y) ? (x) : (y))
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * A Web proxy module. Stages:
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * translate_name: set filename to proxy:<URL>
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * can't trust directory_walk/file_walk since these are
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * not in our filesystem. Prevents mod_http from serving
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * the TRACE request we will set aside to handle later.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * fix_ups: convert the URL stored in the filename to the
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * canonical form.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * handler: handle proxy requests
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* -------------------------------------------------------------- */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* Translate the URL into a 'filename' */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* XXX: EBCDIC safe? --nd */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd ? (x - '0') \
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndstatic unsigned char hex2c(const char* p) {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#define PROXY_COPY_CONF_PARAMS(w, c) \
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd } while (0)
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd const char *key,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd const char *val)
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Worker load factor. Used with BalancerMamber
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * It is a number between 1 and 100 in percents.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "LoadFactor must be number between 1..100";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* If set it will give the retry timeout for the worker
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * The default value is 60 seconds, meaning that if
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * in error state, it will be retried after that timeout.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "Retry must be at least one second";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Time in seconds that will destroy all the connections
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * that exced the smax
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "TTL must be at least one second";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Initial number of connections to remote
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "Min must be a positive number";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Maximum number of connections to remote
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "Max must be a positive number";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* XXX: More inteligent naming needed */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Maximum number of connections to remote that
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * will not be destroyed
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "Smax must be a positive number";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Acquire timeout in milliseconds.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * If set this will be the maximum time to
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * wait for a free connection.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "Acquire must be at least one mili second";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Connection timeout in seconds.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Defaults to server timeout.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "Timeout must be at least one second";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd worker->io_buffer_size = ((s > AP_IOBUFSIZE) ? s : AP_IOBUFSIZE);
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "ReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "KeepAlive must be On|Off";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Worker route.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "Route length must be < 64 characters";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Worker redirection route.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "Redirect length must be < 64 characters";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "unknown Worker parameter";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd const char *key,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd const char *val)
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Balancer sticky session name.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Set to something like JSESSIONID or
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * PHPSESSIONID, etc..,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* If set to 'on' the session will break
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if the worker is in error state or
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * disabled.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "failover must be On|Off";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Balancer timeout in seconds.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * If set this will be the maximum time to
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * wait for a free worker.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Default is not to wait.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "timeout must be at least one second";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Maximum number of failover attempts before
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * giving up.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "maximum number of attempts must be a positive number";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd return "unknown Balancer parameter";
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndstatic int alias_match(const char *uri, const char *alias_fakename)
9472e4d3c410be3b3f1addbf3b1db1769f64e765nd const char *end_fakename = alias_fakename + strlen(alias_fakename);
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh /* any number of '/' in the alias matches any number in
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * the supplied URI, but there must be at least one...
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh /* Other characters are compared literally */
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen /* Other characters are canonicalised and compared literally */
* GET http://othervhost/cgi-bin/printenv HTTP/1.0
#ifdef FIX_15207
int i, len;
: ap_default_port(r))))) {
#ifdef FIX_15207
if (len > 0) {
return DECLINED;
#ifndef FIX_15207
int i, len;
if (r->proxyreq) {
return OK;
#ifndef FIX_15207
if (len > 0) {
return DECLINED;
return OK;
return DECLINED;
&proxy_module);
for (j = 0; j < num_sec; ++j)
if (entry_proxy->r
return OK;
int access_status;
return DECLINED;
return access_status;
return OK;
#ifndef FIX_15207
char *url, *p;
int access_status;
return DECLINED;
#ifdef FIX_15207
return OK;
return access_status;
return HTTP_BAD_REQUEST;
char *nuri;
const char *ref;
return DECLINED;
&r->parsed_uri,
return HTTP_MOVED_PERMANENTLY;
const char *p2;
int direct_connect = 0;
const char *str;
long maxfwd;
return DECLINED;
switch (r->method_number) {
case M_TRACE: {
int access_status;
return OK;
case M_OPTIONS: {
int access_status;
return OK;
if (p == NULL) {
return HTTP_BAD_REQUEST;
return HTTP_MOVED_PERMANENTLY;
int ii;
#if DEBUGGING
r->uri);
return access_status;
if (!direct_connect) {
0,NULL, 0)) ||
goto cleanup;
goto cleanup;
if (balancer) {
return access_status;
return ps;
ps->allowed_connect_ports = apr_array_append(p, base->allowed_connect_ports, overrides->allowed_connect_ports);
ps->recv_buffer_size = (overrides->recv_buffer_size_set == 0) ? base->recv_buffer_size : overrides->recv_buffer_size;
ps->io_buffer_size = (overrides->io_buffer_size_set == 0) ? base->io_buffer_size : overrides->io_buffer_size;
ps->error_override = (overrides->error_override_set == 0) ? base->error_override : overrides->error_override;
ps->preserve_host = (overrides->preserve_host_set == 0) ? base->preserve_host : overrides->preserve_host;
ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status;
return ps;
return (void *) new;
return new;
char *r, *f, *scheme;
int port;
if (regex)
scheme[p-r] = 0;
if (q != NULL) {
if (regex)
if (regex) {
if (!reg)
return NULL;
char *r = NULL;
char *word;
while (*arg) {
f = word;
r = word;
if (!val) {
if (r == NULL)
if (!balancer) {
conf, r);
if (err)
if (err)
if (!worker) {
if (err)
if (err)
return NULL;
&proxy_module);
if ( r == NULL)
return NULL;
&proxy_module);
return NULL;
&proxy_module);
return NULL;
int found = 0;
if (!found) {
return NULL;
int *New;
return NULL;
int found = 0;
if (!found) {
#if DEBUGGING
#if DEBUGGING
#if DEBUGGING
#if DEBUGGING
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
int timeout;
return NULL;
return NULL;
return NULL;
return NULL;
char *word;
while (*arg) {
if (!path)
else if (!name)
if (!val)
if (!path)
if (!name)
if (!worker) {
const char *err;
if (err)
if (!balancer) {
if (err)
return NULL;
const char *err;
if (!balancer) {
if (!worker) {
while (*arg) {
if (!val) {
if (worker)
if (err)
return NULL;
&proxy_module);
const char *errmsg;
return err;
if (!arg) {
return errmsg;
conf->r = r;
return NULL;
{NULL}
if (proxy_ssl_enable) {
if (proxy_ssl_disable) {
return proxy_ssl_disable(c);
return OK;
return OK;
++worker;
++balancer;
return OK;
worker++;
if (!reverse) {
s = s->next;
proxy_lb_workers = 0;
return OK;
#ifndef FIX_15207
#ifndef FIX_15207
request_rec *r,
request_rec *r,
(request_rec *r), (r),