mod_proxy.c revision 144f8db798e3b92e4e4a3f51904e8f21ad160680
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder/* Licensed to the Apache Software Foundation (ASF) under one or more
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * contributor license agreements. See the NOTICE file distributed with
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * this work for additional information regarding copyright ownership.
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder * The ASF licenses this file to You under the Apache License, Version 2.0
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * (the "License"); you may not use this file except in compliance with
b4fbc96e05117839ca409f5f20f97b3ac872d1edTill Mossakowski * the License. You may obtain a copy of the License at
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * http://www.apache.org/licenses/LICENSE-2.0
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder * Unless required by applicable law or agreed to in writing, software
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * distributed under the License is distributed on an "AS IS" BASIS,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * See the License for the specific language governing permissions and
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * limitations under the License.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskiAPR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskiAPR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskiAPR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskiAPR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski#define MAX(x,y) ((x) >= (y) ? (x) : (y))
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * A Web proxy module. Stages:
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * translate_name: set filename to proxy:<URL>
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * can't trust directory_walk/file_walk since these are
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * not in our filesystem. Prevents mod_http from serving
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * the TRACE request we will set aside to handle later.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * fix_ups: convert the URL stored in the filename to the
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * canonical form.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * handler: handle proxy requests
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski/* -------------------------------------------------------------- */
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder/* Translate the URL into a 'filename' */
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski (w)->recv_buffer_size = (c)->recv_buffer_size; \
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski (w)->recv_buffer_size_set = (c)->recv_buffer_size_set; \
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski (w)->io_buffer_size = (c)->io_buffer_size; \
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski (w)->io_buffer_size_set = (c)->io_buffer_size_set; \
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskistatic const char *set_worker_param(apr_pool_t *p,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* Normalized load factor. Used with BalancerMamber,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * it is a number between 1 and 100.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski if (worker->lbfactor < 1 || worker->lbfactor > 100)
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder return "LoadFactor must be number between 1..100";
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* If set it will give the retry timeout for the worker
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * The default value is 60 seconds, meaning that if
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * in error state, it will be retried after that timeout.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski return "Retry must be at least one second";
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* Time in seconds that will destroy all the connections
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * that exced the smax
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski return "TTL must be at least one second";
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* Initial number of connections to remote
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski return "Min must be a positive number";
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* Maximum number of connections to remote
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski return "Max must be a positive number";
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* XXX: More inteligent naming needed */
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* Maximum number of connections to remote that
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * will not be destroyed
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski return "Smax must be a positive number";
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* Acquire timeout in milliseconds.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * If set this will be the maximum time to
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * wait for a free connection.
for (v = val; *v; v++) {
mode = 0;
if (mode)
if (mode)
if (mode)
if (mode)
if (ival == 0)
return NULL;
apr_pool_t *p,
const char *key,
const char *val)
int ival;
if (ival < 0)
if (provider) {
return NULL;
return NULL;
++aliasp;
++urip;
* GET http://othervhost/cgi-bin/printenv HTTP/1.0
: ap_default_port(r))))) {
return DECLINED;
const char *start;
const char *end;
const char *var;
const char *val;
const char *firstpart;
return str;
return str;
sizeof (struct proxy_alias));
return ret;
int i, len;
&proxy_module);
const char *fake;
const char *real;
if (r->proxyreq) {
return OK;
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;
char *url, *p;
int access_status;
&proxy_module);
return DECLINED;
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;
return HTTP_FORBIDDEN;
return HTTP_REQUEST_ENTITY_TOO_LARGE;
if (p == NULL) {
return HTTP_BAD_REQUEST;
return HTTP_MOVED_PERMANENTLY;
!direct_connect; i++) {
#if DEBUGGING
r->uri);
return access_status;
if (!worker)
goto cleanup;
if (!direct_connect) {
goto cleanup;
if (balancer)
if (balancer) {
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)
return NULL;
if (!balancer) {
conf, r);
if (err)
if (err)
if (!worker) {
if (err)
if (err)
return NULL;
if ( r == NULL)
return NULL;
return NULL;
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;
int in_proxy_section = 0;
if (!balancer) {
if (in_proxy_section) {
if (err)
if (!worker) {
if (in_proxy_section) {
if (err)
while (*arg) {
if (!val) {
if (worker)
if (err)
return NULL;
&proxy_module);
const char *errmsg;
return err;
if (!arg) {
return errmsg;
conf->r = r;
NULL);
NULL);
if (!balancer) {
if (err)
conf->p);
if (!worker) {
if (err)
NULL);
while (*arg) {
if (!val) {
if (worker)
if (err)
return NULL;
{NULL}
if (proxy_ssl_enable) {
if (proxy_ssl_disable) {
return proxy_ssl_disable(c);
if (proxy_is_https) {
return proxy_is_https(c);
const char *var)
if (proxy_ssl_val) {
return NULL;
return OK;
return OK;
++worker;
++balancer;
return OK;
worker++;
if (!reverse) {
s = s->next;
proxy_lb_workers = 0;
return OK;
request_rec *r,
request_rec *r,
(request_rec *r), (r),
(status, r),