mod_proxy.c revision bda7a7d57377f45932c237d5aba00b189d85c2a9
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens Elkner * applicable.
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova * Licensed under the Apache License, Version 2.0 (the "License");
94e2e03f6efde106de095ef4ea0ec87f74955a31Kristina Sojakova * you may not use this file except in compliance with the License.
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu * You may obtain a copy of the License at
94e2e03f6efde106de095ef4ea0ec87f74955a31Kristina Sojakova * http://www.apache.org/licenses/LICENSE-2.0
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova * Unless required by applicable law or agreed to in writing, software
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova * distributed under the License is distributed on an "AS IS" BASIS,
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova * See the License for the specific language governing permissions and
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova * limitations under the License.
f588d2cfbdd1e6d4855df164fce25cf7db1a8e2dChristian MaederAPR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaAPR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaAPR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaAPR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova#define MAX(x,y) ((x) >= (y) ? (x) : (y))
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova * A Web proxy module. Stages:
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova * translate_name: set filename to proxy:<URL>
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova * can't trust directory_walk/file_walk since these are
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova * not in our filesystem. Prevents mod_http from serving
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * the TRACE request we will set aside to handle later.
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * fix_ups: convert the URL stored in the filename to the
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * canonical form.
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * handler: handle proxy requests
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova/* -------------------------------------------------------------- */
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova/* Translate the URL into a 'filename' */
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova (w)->recv_buffer_size = (c)->recv_buffer_size; \
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova (w)->recv_buffer_size_set = (c)->recv_buffer_size_set; \
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova (w)->io_buffer_size = (c)->io_buffer_size; \
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder (w)->io_buffer_size_set = (c)->io_buffer_size_set; \
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakovastatic const char *set_worker_param(apr_pool_t *p,
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova /* Normalized load factor. Used with BalancerMamber,
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder * it is a number between 1 and 100.
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova if (worker->lbfactor < 1 || worker->lbfactor > 100)
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova return "LoadFactor must be number between 1..100";
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova /* If set it will give the retry timeout for the worker
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * The default value is 60 seconds, meaning that if
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder * in error state, it will be retried after that timeout.
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova return "Retry must be at least one second";
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova /* Time in seconds that will destroy all the connections
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * that exced the smax
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder return "TTL must be at least one second";
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova /* Initial number of connections to remote
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova return "Min must be a positive number";
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova /* Maximum number of connections to remote
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova return "Max must be a positive number";
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova /* XXX: More inteligent naming needed */
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova /* Maximum number of connections to remote that
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder * will not be destroyed
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova return "Smax must be a positive number";
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova /* Acquire timeout in milliseconds.
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder * If set this will be the maximum time to
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * wait for a free connection.
e0f1794e365dd347e97b37d7d22b2fce27296fa1Christian Maeder return "Acquire must be at least one mili second";
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova worker->acquire = apr_time_make(0, ival * 1000);
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova /* Connection timeout in seconds.
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova * Defaults to server timeout.
return NULL;
const char *key,
const char *val)
int ival;
if (ival < 0)
return NULL;
++aliasp;
++urip;
* GET http://othervhost/cgi-bin/printenv HTTP/1.0
: ap_default_port(r))))) {
return DECLINED;
int i, len;
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;
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 (!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;
&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);
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),