mod_proxy.c revision 97e6385784e04f68e54477610f3339fc0e2dcd86
f545d156561c08020a67f9640c51454c2df4fb57fabien/* Copyright 1999-2004 The Apache Software Foundation
a1d62218cdb0efd0f02da1b54fd3eda91a681d98nd * Licensed under the Apache License, Version 2.0 (the "License");
f545d156561c08020a67f9640c51454c2df4fb57fabien * you may not use this file except in compliance with the License.
5bc4a8b692477b73472be5370991e247cc72fc8algentis * You may obtain a copy of the License at
f545d156561c08020a67f9640c51454c2df4fb57fabien * Unless required by applicable law or agreed to in writing, software
f545d156561c08020a67f9640c51454c2df4fb57fabien * distributed under the License is distributed on an "AS IS" BASIS,
f545d156561c08020a67f9640c51454c2df4fb57fabien * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f545d156561c08020a67f9640c51454c2df4fb57fabien * See the License for the specific language governing permissions and
f545d156561c08020a67f9640c51454c2df4fb57fabien * limitations under the License.
f545d156561c08020a67f9640c51454c2df4fb57fabienAPR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
f545d156561c08020a67f9640c51454c2df4fb57fabienAPR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
f545d156561c08020a67f9640c51454c2df4fb57fabien#define MAX(x,y) ((x) >= (y) ? (x) : (y))
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis * A Web proxy module. Stages:
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis * translate_name: set filename to proxy:<URL>
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis * can't trust directory_walk/file_walk since these are
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis * not in our filesystem. Prevents mod_http from serving
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis * the TRACE request we will set aside to handle later.
f545d156561c08020a67f9640c51454c2df4fb57fabien * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
f545d156561c08020a67f9640c51454c2df4fb57fabien * fix_ups: convert the URL stored in the filename to the
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis * canonical form.
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis * handler: handle proxy requests
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis/* -------------------------------------------------------------- */
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis/* Translate the URL into a 'filename' */
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis/* XXX: EBCDIC safe? --nd */
f545d156561c08020a67f9640c51454c2df4fb57fabien ? (x - '0') \
6d9670505469513b81e72cb3941ee58d3fd08f6elgentisstatic unsigned char hex2c(const char* p) {
0e48414563f4e1b5edb1f95518b25547a499ed79lgentisstatic const char *set_worker_param(proxy_worker *worker,
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis const char *key,
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis const char *val)
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis return "loadfactor must be number between 1..100";
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis return "retry must be al least one second";
f545d156561c08020a67f9640c51454c2df4fb57fabien return "ttl must be al least one second";
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis return "min must be a positive number";
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis return "max must be a positive number";
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis /* XXX: More inteligent naming needed */
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis return "smax must be a positive number";
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis return "unknown parameter";
0e48414563f4e1b5edb1f95518b25547a499ed79lgentisstatic const char *set_balancer_param(proxy_balancer *balancer,
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis const char *key,
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis const char *val)
5bc4a8b692477b73472be5370991e247cc72fc8algentis return "failover must be On|Off";
5bc4a8b692477b73472be5370991e247cc72fc8algentis return "timeout must be al least one second";
5bc4a8b692477b73472be5370991e247cc72fc8algentis return "unknown parameter";
5bc4a8b692477b73472be5370991e247cc72fc8algentisstatic int alias_match(const char *uri, const char *alias_fakename)
5bc4a8b692477b73472be5370991e247cc72fc8algentis const char *end_fakename = alias_fakename + strlen(alias_fakename);
5bc4a8b692477b73472be5370991e247cc72fc8algentis /* any number of '/' in the alias matches any number in
5bc4a8b692477b73472be5370991e247cc72fc8algentis * the supplied URI, but there must be at least one...
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis /* Other characters are compared literally */
0e48414563f4e1b5edb1f95518b25547a499ed79lgentis /* Other characters are canonicalised and compared literally */
f545d156561c08020a67f9640c51454c2df4fb57fabien /* fixup badly encoded stuff (e.g. % as last character) */
f545d156561c08020a67f9640c51454c2df4fb57fabien /* Check last alias path component matched all the way */
f545d156561c08020a67f9640c51454c2df4fb57fabien if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')
5bc4a8b692477b73472be5370991e247cc72fc8algentis /* Return number of characters from URI which matched (may be
f545d156561c08020a67f9640c51454c2df4fb57fabien * greater than length of alias, since we may have matched
5bc4a8b692477b73472be5370991e247cc72fc8algentis * doubled slashes)
5bc4a8b692477b73472be5370991e247cc72fc8algentis/* Detect if an absoluteURI should be proxied or not. Note that we
f545d156561c08020a67f9640c51454c2df4fb57fabien * have to do this during this phase because later phases are
f545d156561c08020a67f9640c51454c2df4fb57fabien * "short-circuiting"... i.e. translate_names will end when the first
f545d156561c08020a67f9640c51454c2df4fb57fabien * module returns OK. So for example, if the request is something like:
f545d156561c08020a67f9640c51454c2df4fb57fabien * mod_alias will notice the /cgi-bin part and ScriptAlias it and
f545d156561c08020a67f9640c51454c2df4fb57fabien * short-circuit the proxy... just because of the ordering in the
f545d156561c08020a67f9640c51454c2df4fb57fabien * configuration file.
f545d156561c08020a67f9640c51454c2df4fb57fabien (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
f545d156561c08020a67f9640c51454c2df4fb57fabien struct proxy_alias *ent = (struct proxy_alias *)conf->aliases->elts;
f545d156561c08020a67f9640c51454c2df4fb57fabien /* Ick... msvc (perhaps others) promotes ternary short results to int */
5bc4a8b692477b73472be5370991e247cc72fc8algentis /* but it might be something vhosted */
5bc4a8b692477b73472be5370991e247cc72fc8algentis && !strcasecmp(r->parsed_uri.scheme, ap_http_method(r))
5bc4a8b692477b73472be5370991e247cc72fc8algentis && ap_matches_request_vhost(r, r->parsed_uri.hostname,
f545d156561c08020a67f9640c51454c2df4fb57fabien (apr_port_t)(r->parsed_uri.port_str ? r->parsed_uri.port
f545d156561c08020a67f9640c51454c2df4fb57fabien r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
f545d156561c08020a67f9640c51454c2df4fb57fabien /* We need special treatment for CONNECT proxying: it has no scheme part */
f545d156561c08020a67f9640c51454c2df4fb57fabien r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
f545d156561c08020a67f9640c51454c2df4fb57fabien /* test for a ProxyPass */
f545d156561c08020a67f9640c51454c2df4fb57fabien r->filename = apr_pstrcat(r->pool, "proxy:", ent[i].real,
f545d156561c08020a67f9640c51454c2df4fb57fabien (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
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) {
return access_status;
return HTTP_FORBIDDEN;
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;
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;
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;
name = f;
sticky = r;
sticky = f;
if (r == NULL)
if (!balancer)
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;
#ifndef FIX_15207
#ifndef FIX_15207
request_rec *r,
request_rec *r,
(request_rec *r), (r),