mod_proxy.c revision c64fb33e0c4634fd352c4a6c143cd1a087c09b13
f743002678eb67b99bbc29fee116b65d9530fec0wrowe/* Licensed to the Apache Software Foundation (ASF) under one or more
80833bb9a1bf25dcf19e814438a4b311d2e1f4cffuankg * contributor license agreements. See the NOTICE file distributed with
a34684a59b60a4173c25035d0c627ef17e6dc215rpluem * this work for additional information regarding copyright ownership.
1337c7673efc1f80f634139fbad7cbb98a0dc657ylavic * The ASF licenses this file to You under the Apache License, Version 2.0
1337c7673efc1f80f634139fbad7cbb98a0dc657ylavic * (the "License"); you may not use this file except in compliance with
1337c7673efc1f80f634139fbad7cbb98a0dc657ylavic * the License. You may obtain a copy of the License at
4da61833a1cbbca94094f9653fd970582b97a72etrawick * Unless required by applicable law or agreed to in writing, software
4da61833a1cbbca94094f9653fd970582b97a72etrawick * distributed under the License is distributed on an "AS IS" BASIS,
4da61833a1cbbca94094f9653fd970582b97a72etrawick * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4789804be088bcd86ae637a29cdb7fda25169521jailletc * See the License for the specific language governing permissions and
4789804be088bcd86ae637a29cdb7fda25169521jailletc * limitations under the License.
0a0df13b7f1f4f1a74fe295253d89ca3911b301aylavicAPR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
0a0df13b7f1f4f1a74fe295253d89ca3911b301aylavicAPR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
0a0df13b7f1f4f1a74fe295253d89ca3911b301aylavicAPR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
506bfe33206b2fece40ef25f695af39dd4130facjkaluza#define MAX(x,y) ((x) >= (y) ? (x) : (y))
2e6f4d654c96c98b761fb012fd25c5d5b1558c44sf * A Web proxy module. Stages:
2e6f4d654c96c98b761fb012fd25c5d5b1558c44sf * translate_name: set filename to proxy:<URL>
17e6c95f3b22d18acdf8380fb26a8d0e10c80767ylavic * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
17e6c95f3b22d18acdf8380fb26a8d0e10c80767ylavic * can't trust directory_walk/file_walk since these are
17e6c95f3b22d18acdf8380fb26a8d0e10c80767ylavic * not in our filesystem. Prevents mod_http from serving
17e6c95f3b22d18acdf8380fb26a8d0e10c80767ylavic * the TRACE request we will set aside to handle later.
17e6c95f3b22d18acdf8380fb26a8d0e10c80767ylavic * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
e8bd80a4bb88199d2f9a24a50345688e52d9c116ylavic * fix_ups: convert the URL stored in the filename to the
e8bd80a4bb88199d2f9a24a50345688e52d9c116ylavic * canonical form.
e8bd80a4bb88199d2f9a24a50345688e52d9c116ylavic * handler: handle proxy requests
330e16bea8fe9cace4de90c349750c03dfb1fe64ylavic/* -------------------------------------------------------------- */
330e16bea8fe9cace4de90c349750c03dfb1fe64ylavic/* Translate the URL into a 'filename' */
d7205b1a86c51c27b71a2c458dc453fd53a261c1covener (w)->recv_buffer_size_set = (c)->recv_buffer_size_set; \
44ff304057225e944e220e981d434a046d14cf06covener (w)->io_buffer_size_set = (c)->io_buffer_size_set; \
44ff304057225e944e220e981d434a046d14cf06covener } while (0)
5d1ba75b8794925e67591c209085a49279791de9covener const char *key,
5d1ba75b8794925e67591c209085a49279791de9covener const char *val)
caad2986f81ab263f7af41467dd622dc9add17f3ylavic /* Normalized load factor. Used with BalancerMamber,
caad2986f81ab263f7af41467dd622dc9add17f3ylavic * it is a number between 1 and 100.
45a10d38e6051fd7bdf9d742aaae633d97ff02abjailletc if (worker->lbfactor < 1 || worker->lbfactor > 100)
f7317ff316c2b141feea31bddb74d5d3fa1584edjorton return "LoadFactor must be number between 1..100";
a34684a59b60a4173c25035d0c627ef17e6dc215rpluem /* If set it will give the retry timeout for the worker
a34684a59b60a4173c25035d0c627ef17e6dc215rpluem * The default value is 60 seconds, meaning that if
1e2d421a36999d292042a5539971070d54aa6c63ylavic * in error state, it will be retried after that timeout.
fa7ed98b9dc94c5845cf845aea0a44ecacd290c9humbedooh return "Retry must be a positive value";
0b67eb8568cd58bb77082703951679b42cf098actrawick /* Time in seconds that will destroy all the connections
5ef3c61605a3a021ff71f488983cb0065f8e1a79covener * that exced the smax
6502b7b32f980cc2093bb3ebce37e5e4dc68fba4ylavic return "TTL must be at least one second";
c1a63b8fad09c419c1a64f75993feb8a343a6801ylavic /* Initial number of connections to remote
e466c40e1801982602ee0200c9e8b61cc148742djailletc return "Min must be a positive number";
04983e3bd1754764eec7d6bb772fe3b0bf391771jorton /* Maximum number of connections to remote
15660979a30d251681463de2e0584853890082accovener return "Max must be a positive number";
cfd9415521847b2f9394fad04fb701cfb955f503rjung /* XXX: More inteligent naming needed */
cfd9415521847b2f9394fad04fb701cfb955f503rjung /* Maximum number of connections to remote that
28c31fb73c1264bd1d0ff932573677030b024c7dwrowe * will not be destroyed
28c31fb73c1264bd1d0ff932573677030b024c7dwrowe return "Smax must be a positive number";
63b9f1f5880391261705f696d7d65507bbe9ace3covener /* Acquire timeout in milliseconds.
49dacedb6c387b786b7911082ff35121a45f414bcovener * If set this will be the maximum time to
49dacedb6c387b786b7911082ff35121a45f414bcovener * wait for a free connection.
3c990331fc6702119e4f5b8ba9eae3021aea5265jim return "Acquire must be at least one mili second";
fc42512879dd0504532f52fe5d0d0383dda96a1eniq /* Connection timeout in seconds.
0451df5dc50fa5d8b3e07d92ee6a92e36a1181a5niq * Defaults to server timeout.
983528026996668ea295be95aedb9c7a346af470ylavic return "Timeout must be at least one second";
15890c9306ba98f6fc243e15a3c4778ddc7d773erpluem worker->io_buffer_size = ((s > AP_IOBUFSIZE) ? s : AP_IOBUFSIZE);
b54b024c06a19926832d77d40ba35ad8c41e4d3dminfrin return "ReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
75f5c2db254c0167a0e396254460de09b775d203trawick return "KeepAlive must be On|Off";
4f0358189bfa57b8e75bd6b94db264302a8f336amrumph /* Worker route.
5716f9c6daa92dde5f2f9d11ed63f7c9549c223atrawick return "Route length must be < 64 characters";
54d750a84a175d8e338880514d440773eb986b50covener /* Worker redirection route.
54d750a84a175d8e338880514d440773eb986b50covener return "Redirect length must be < 64 characters";
7a3aa12f0eda24793ee26d6a179bd53132e9dae8covener const char *v;
54d750a84a175d8e338880514d440773eb986b50covener /* Worker status.
4e30ef014533a7e93c92d88306291f5e49c9692ftrawick for (v = val; *v; v++) {
83b50288fa7d306324bba68832011ea08f5c7832covener if (*v == '+') {
2e15620d724fb8e3a5be183b917359a2fd6e9468covener else if (*v == '-') {
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza return "Unknown status parameter option";
001a44c352f89c9ec332ffd3e0a6927dcd19432chumbedooh return "flushpackets must be on|off|auto";
9b0076ddd1103e5fa9c1f9bafde4b06ce244fbaecovener return "flushwait must be <= 1000, or 0 for system default of 10 millseconds.";
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza worker->flush_wait = ival * 1000; /* change to microseconds */
56589be3d7a3e9343370df240010c6928cc78b39jkaluza /* Ping/Pong timeout in seconds.
77ca16c5676da23155311e13cee61e7eaba9fa3ejailletc return "Ping/Pong timeout must be at least one second";
4d12805e6c18253040223ea637acd6b3b3c18f60jorton return "lbset must be between 0 and 99";
a4df2cd1e1391575a327c2a90ba4315f805a0a78covener return "unknown Worker parameter";
6a80c3c6f4b8ea7ba5e89402b8b779b09ce020e0covenerstatic const char *set_balancer_param(proxy_server_conf *conf,
75a230a728338d84dcfe81edd375352f34de22d0covener const char *key,
75a230a728338d84dcfe81edd375352f34de22d0covener const char *val)
63a5ea80bddcc84a462e40f402b4f330e0e05411covener /* Balancer sticky session name.
63a5ea80bddcc84a462e40f402b4f330e0e05411covener * Set to something like JSESSIONID or
63a5ea80bddcc84a462e40f402b4f330e0e05411covener * PHPSESSIONID, etc..,
a511a29faf2ff7ead3b67680154a624effb31aafminfrin /* If set to 'on' the session will break
a511a29faf2ff7ead3b67680154a624effb31aafminfrin * if the worker is in error state or
a511a29faf2ff7ead3b67680154a624effb31aafminfrin * disabled.
6d601599d3d65df0410eae6e573e75b2dbfb1fb4minfrin return "failover must be On|Off";
6d601599d3d65df0410eae6e573e75b2dbfb1fb4minfrin /* Balancer timeout in seconds.
684e0cfc200f66287a93bbd1708d1dd8a92a7eefcovener * If set this will be the maximum time to
684e0cfc200f66287a93bbd1708d1dd8a92a7eefcovener * wait for a free worker.
5c43d2fb853f84497b5ece2d414ef9484aa87e5fsf * Default is not to wait.
26c5829347f6a355c00f1ba0301d575056b69536niq return "timeout must be at least one second";
ef82e8fa164e0a1f8b813f7deb6b7ead96018c94niq /* Maximum number of failover attempts before
ef82e8fa164e0a1f8b813f7deb6b7ead96018c94niq * giving up.
c12917da693bae4028a1d5a5e8224bceed8c739dsf return "maximum number of attempts must be a positive number";
4576c1a9ef54cd1e5555ee07d016a7f559f80338sf return "unknown lbmethod";
9811aed12bbc71783d2e544ccb5fecd193843eadsf return "unknown Balancer parameter";
bd3f5647b96d378d9c75c954e3f13582af32c643sfstatic int alias_match(const char *uri, const char *alias_fakename)
bd3f5647b96d378d9c75c954e3f13582af32c643sf const char *end_fakename = alias_fakename + strlen(alias_fakename);
584a85dd4047e38d3ed3a29b6662fcc9d100ae4csf /* any number of '/' in the alias matches any number in
584a85dd4047e38d3ed3a29b6662fcc9d100ae4csf * the supplied URI, but there must be at least one...
85eacfc96a04547ef25aabbc06440039715084c2jorton /* Other characters are compared literally */
79c5787b92ac5f0e1cc82393816c77a006399316trawick /* fixup badly encoded stuff (e.g. % as last character) */
79c5787b92ac5f0e1cc82393816c77a006399316trawick /* We reach the end of the uri before the end of "alias_fakename"
79c5787b92ac5f0e1cc82393816c77a006399316trawick * for example uri is "/" and alias_fakename "/examples"
536e48c08d674acac5d44929318f2ad928edc361jorton /* Check last alias path component matched all the way */
e81785da447b469da66f218b3f0244aab507958djorton if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')
3e4e54d4e3fc0123c63d57aa84ac7ad7a8c73ff8jorton /* Return number of characters from URI which matched (may be
3e4e54d4e3fc0123c63d57aa84ac7ad7a8c73ff8jorton * greater than length of alias, since we may have matched
53e9b27aba029b18be814df40bcf6f0428771d1efuankg * doubled slashes)
6bb524f1895f30265a1431afc460977d391cb36bsf/* Detect if an absoluteURI should be proxied or not. Note that we
ca61ccd0c306c2c72df153688ba1b49f3eceed80sf * have to do this during this phase because later phases are
6bb524f1895f30265a1431afc460977d391cb36bsf * "short-circuiting"... i.e. translate_names will end when the first
e6dd71992459d05a676b98b7963423dc5dc1e24aminfrin * module returns OK. So for example, if the request is something like:
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin * mod_alias will notice the /cgi-bin part and ScriptAlias it and
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin * short-circuit the proxy... just because of the ordering in the
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin * configuration file.
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung /* Ick... msvc (perhaps others) promotes ternary short results to int */
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick /* but it might be something vhosted */
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick && !strcasecmp(r->parsed_uri.scheme, ap_http_scheme(r))
ae600ca541efc686b34f8b1f21bd3d0741d37674covener && ap_matches_request_vhost(r, r->parsed_uri.hostname,
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick (apr_port_t)(r->parsed_uri.port_str ? r->parsed_uri.port
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim /* We need special treatment for CONNECT proxying: it has no scheme part */
cfa64348224b66dd1c9979b809406c4d15b1c137fielding else if (conf->req && r->method_number == M_CONNECT
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;
return DECLINED;
regm);
NULL);
if (len != 0) {
return DECLINED;
if (found) {
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_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 (!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) {
if (is_regex) {
f = word;
r = word;
if (!val) {
if (r == NULL)
if (use_regex) {
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),