mod_proxy.c revision e1f43cac62f6960a6945e1fb6e3288ef7082ac53
55cf6e01272ec475edea32aa9b7923de2d36cb42Christian Maeder/* Licensed to the Apache Software Foundation (ASF) under one or more
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * contributor license agreements. See the NOTICE file distributed with
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * this work for additional information regarding copyright ownership.
b43458b4d81f7451112cecbd757f3a05216e7088Kristina Sojakova * The ASF licenses this file to You under the Apache License, Version 2.0
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * (the "License"); you may not use this file except in compliance with
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * the License. You may obtain a copy of the License at
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * http://www.apache.org/licenses/LICENSE-2.0
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * Unless required by applicable law or agreed to in writing, software
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * distributed under the License is distributed on an "AS IS" BASIS,
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * See the License for the specific language governing permissions and
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * limitations under the License.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina SojakovaAPR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina SojakovaAPR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina SojakovaAPR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina SojakovaAPR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova#define MAX(x,y) ((x) >= (y) ? (x) : (y))
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovastatic const char * const proxy_id = "proxy";
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * A Web proxy module. Stages:
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * translate_name: set filename to proxy:<URL>
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * can't trust directory_walk/file_walk since these are
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * not in our filesystem. Prevents mod_http from serving
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * the TRACE request we will set aside to handle later.
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova * fix_ups: convert the URL stored in the filename to the
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova * canonical form.
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova * handler: handle proxy requests
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova/* -------------------------------------------------------------- */
a669e4685b32ff5ca1bca785eacc5e30a545b010Christian Maeder/* Translate the URL into a 'filename' */
b43458b4d81f7451112cecbd757f3a05216e7088Kristina Sojakovastatic const char *set_worker_param(apr_pool_t *p,
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova /* Normalized load factor. Used with BalancerMamber,
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * it is a number between 1 and 100.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova if (worker->s->lbfactor < 1 || worker->s->lbfactor > 100)
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova return "LoadFactor must be a number between 1..100";
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova /* If set it will give the retry timeout for the worker
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * The default value is 60 seconds, meaning that if
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * in error state, it will be retried after that timeout.
80d2ec8f37d5ddec13c14b17b1bab01e9c94630aChristian Maeder return "Retry must be a positive value";
a669e4685b32ff5ca1bca785eacc5e30a545b010Christian Maeder worker->s->retry = apr_time_from_sec(ival);
a669e4685b32ff5ca1bca785eacc5e30a545b010Christian Maeder /* Time in seconds that will destroy all the connections
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova * that exceed the smax
b3bacd257ffcdd346b70ab690f03b28ad5f33fdcKristina Sojakova return "TTL must be at least one second";
b3bacd257ffcdd346b70ab690f03b28ad5f33fdcKristina Sojakova /* Initial number of connections to remote
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova return "Min must be a positive number";
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova /* Maximum number of connections to remote
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova return "Max must be a positive number";
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova /* XXX: More inteligent naming needed */
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova /* Maximum number of connections to remote that
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * will not be destroyed
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova return "Smax must be a positive number";
b2e01ef1b5d4c7a62260eb792291e8e1b10e545bIulia Ignatov /* Acquire timeout in given unit (default is milliseconds).
for (v = val; *v; v++) {
mode = 0;
if (ival == 0)
return NULL;
apr_pool_t *p,
const char *key,
const char *val)
int ival;
char *path;
if (ival < 0)
if (provider) {
return NULL;
char *val_split;
char *status;
char *tok_state;
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 len;
const char *fake;
const char *real;
int mismatch = 0;
return DECLINED;
if (!found) {
return HTTP_INTERNAL_SERVER_ERROR;
if (len != 0) {
return DECLINED;
if (mismatch) {
if (found) {
return OK;
return DONE;
if (r->proxyreq) {
return OK;
return DECLINED;
return rv;
&proxy_module);
return rv;
return DECLINED;
&proxy_module);
for (j = 0; j < num_sec; ++j)
int nmatch = 0;
if (entry_proxy->r) {
if (!rxpool) {
for (i = 0; i < nmatch; i++) {
proxyname, 0) :
if (rxpool) {
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;
return DECLINED;
char *end;
else if (maxfwd == 0) {
switch (r->method_number) {
case M_TRACE: {
int access_status;
return OK;
case M_OPTIONS: {
int access_status;
return OK;
if (maxfwd >= 0) {
return HTTP_METHOD_NOT_ALLOWED;
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 (balancer) {
if (!direct_connect) {
const char *cl_a;
char *end;
goto cleanup;
if (cl_a) {
if (cl > 0) {
goto cleanup;
goto cleanup;
if (balancer) {
if (balancer) {
goto cleanup;
return access_status;
return ps;
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->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status;
ps->source_address = (overrides->source_address_set == 0) ? base->source_address : overrides->source_address;
return ps;
const char *arg)
return NULL;
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 *ptr;
char *ret, *c;
if (c == NULL) {
return NULL;
return ret;
return url;
char *r = NULL;
char *word;
unsigned int flags = 0;
const char *err;
if (err) {
return err;
while (*arg) {
if (is_regex) {
f = word;
r = word;
if (!val) {
if (r == NULL) {
if (apr_fnmatch_test(f)) {
if (use_regex) {
return NULL;
char *fake_copy;
if (use_regex) {
fake_copy = f;
if (!balancer) {
if (err)
if (err)
int reuse = 0;
if (!worker) {
if (err)
if (reuse) {
if (err)
return NULL;
const char *fake;
const char *real;
const char *interp;
const char *err;
if (err) {
return err;
fake = f;
real = r;
interp = i;
real = f;
interp = r;
return NULL;
const char *r, const char *interp)
return NULL;
const char *r, const char *interp)
return NULL;
int found = 0;
if (!found) {
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;
return NULL;
int timeout;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
char *word;
int reuse = 0;
if (err)
return err;
while (*arg) {
char *val;
if (!val) {
if (!path)
else if (!name)
if (!path)
if (!name)
if (!balancer) {
if (err)
if (!worker) {
if (reuse) {
if (err)
return NULL;
int in_proxy_section = 0;
if (err)
return err;
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)
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 rv;
return OK;
return OK;
++worker;
++balancer;
return OK;
if (!reverse) {
s = s->next;
APR_LOCK_DEFAULT, 0);
proxy_lb_workers = 0;
return OK;
/* register optional functions within proxy_util.c */
request_rec *r,
request_rec *r,
(request_rec *r), (r),
(status, r),