mod_proxy.c revision 759554f16128a82e3781510c480784b227843b46
d29201dd5328b88140ce050100693c501852657dChristian Maeder/* ====================================================================
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * The Apache Software License, Version 1.1
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * Redistribution and use in source and binary forms, with or without
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * modification, are permitted provided that the following conditions
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * 1. Redistributions of source code must retain the above copyright
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * notice, this list of conditions and the following disclaimer.
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * 2. Redistributions in binary form must reproduce the above copyright
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * notice, this list of conditions and the following disclaimer in
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * the documentation and/or other materials provided with the
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * distribution.
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * 3. The end-user documentation included with the redistribution,
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * if any, must include the following acknowledgment:
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * "This product includes software developed by the
bb4d3b6e93db1495f02de46aff5076862e30517bChristian Maeder * Apache Software Foundation (http://www.apache.org/)."
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * Alternately, this acknowledgment may appear in the software itself,
70e83495a9753d2a104a9869ac2a997ac30d05c1Christian Maeder * if and wherever such third-party acknowledgments normally appear.
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * 4. The names "Apache" and "Apache Software Foundation" must
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * not be used to endorse or promote products derived from this
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * software without prior written permission. For written
bb4d3b6e93db1495f02de46aff5076862e30517bChristian Maeder * permission, please contact apache@apache.org.
21b18016469e574bd145ad07c7b0f02839677cc3Christian Maeder * 5. Products derived from this software may not be called "Apache",
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * nor may "Apache" appear in their name, without prior written
62d8627183cce49c052386186ad69c95b1aa3953Christian Maeder * permission of the Apache Software Foundation.
e9490701e16d1e8abd995ef876d6f937da93b412Christian Maeder * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
616b72452ce5a75ade1a11ccc2c9671b3444558eChristian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
616b72452ce5a75ade1a11ccc2c9671b3444558eChristian Maeder * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * SUCH DAMAGE.
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * ====================================================================
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * This software consists of voluntary contributions made by many
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * individuals on behalf of the Apache Software Foundation. For more
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * information on the Apache Software Foundation, please see
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * Portions of this software are based upon public domain software
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * originally written at the National Center for Supercomputing Applications,
21b18016469e574bd145ad07c7b0f02839677cc3Christian Maeder * University of Illinois, Urbana-Champaign.
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maederextern module AP_MODULE_DECLARE_DATA proxy_module;
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * A Web proxy module. Stages:
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * translate_name: set filename to proxy:<URL>
7862e8fb34d79382e93b45ce894acdd928da8a51Christian Maeder * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder * can't trust directory_walk/file_walk since these are
bb4d3b6e93db1495f02de46aff5076862e30517bChristian Maeder * not in our filesystem. Prevents mod_http from serving
bb4d3b6e93db1495f02de46aff5076862e30517bChristian Maeder * the TRACE request we will set aside to handle later.
21b18016469e574bd145ad07c7b0f02839677cc3Christian Maeder * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
21b18016469e574bd145ad07c7b0f02839677cc3Christian Maeder * fix_ups: convert the URL stored in the filename to the
722e8a91f69209ba0e99bf799c4989801d78cf16Christian Maeder * canonical form.
e0f1794e365dd347e97b37d7d22b2fce27296fa1Christian Maeder * handler: handle proxy requests
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder/* -------------------------------------------------------------- */
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder/* Translate the URL into a 'filename' */
62d8627183cce49c052386186ad69c95b1aa3953Christian Maederstatic int alias_match(const char *uri, const char *alias_fakename)
62d8627183cce49c052386186ad69c95b1aa3953Christian Maeder const char *end_fakename = alias_fakename + strlen(alias_fakename);
62d8627183cce49c052386186ad69c95b1aa3953Christian Maeder const char *aliasp = alias_fakename, *urip = uri;
f876a858a3644fa16b793afb4692cf353fa13762Christian Maeder /* any number of '/' in the alias matches any number in
f876a858a3644fa16b793afb4692cf353fa13762Christian Maeder * the supplied URI, but there must be at least one...
2b470a98ae13b1a87d53f64c3188c8ea77600d99Christian Maeder /* Other characters are compared literally */
03db3efebb43c12041915cb7ffcc172b191208f9Christian Maeder /* Check last alias path component matched all the way */
* 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 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 rc;
if (p == NULL)
return HTTP_BAD_REQUEST;
return HTTP_MOVED_PERMANENTLY;
int ii;
#if DEBUGGING
r->uri);
if (!direct_connect) {
return access_status;
r->uri);
return HTTP_FORBIDDEN;
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->error_override = (overrides->error_override_set == 0) ? base->error_override : overrides->error_override;
return ps;
return (void *) new;
return new;
char *r, *f, *scheme;
int port;
scheme[p-r] = 0;
if (q != NULL) {
return NULL;
if ( r== NULL)
return NULL;
&proxy_module);
if ( r == 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;
&proxy_module);
const char *errmsg;
return err;
if (!arg) {
return errmsg;
conf->r = r;
return NULL;
{NULL}