mod_proxy.c revision fa861fc5a880d2c3a5ecc0ec71fa7da556adf5c1
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * Redistribution and use in source and binary forms, with or without
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * modification, are permitted provided that the following conditions
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 1. Redistributions of source code must retain the above copyright
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * notice, this list of conditions and the following disclaimer.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 2. Redistributions in binary form must reproduce the above copyright
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * notice, this list of conditions and the following disclaimer in
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * the documentation and/or other materials provided with the
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * distribution.
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * 3. The end-user documentation included with the redistribution,
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes * if any, must include the following acknowledgment:
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * "This product includes software developed by the
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * Apache Software Foundation (http://www.apache.org/)."
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * Alternately, this acknowledgment may appear in the software itself,
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * if and wherever such third-party acknowledgments normally appear.
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * 4. The names "Apache" and "Apache Software Foundation" must
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * not be used to endorse or promote products derived from this
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes * software without prior written permission. For written
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes * permission, please contact apache@apache.org.
42a58c2174dae6edfc97af967add2f50baa85800jim * 5. Products derived from this software may not be called "Apache",
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * nor may "Apache" appear in their name, without prior written
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * permission of the Apache Software Foundation.
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * SUCH DAMAGE.
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * ====================================================================
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes * This software consists of voluntary contributions made by many
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * individuals on behalf of the Apache Software Foundation. For more
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * information on the Apache Software Foundation, please see
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * Portions of this software are based upon public domain software
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * originally written at the National Center for Supercomputing Applications,
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * University of Illinois, Urbana-Champaign.
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantzextern module AP_MODULE_DECLARE_DATA proxy_module;
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes#define MAX(x,y) ((x) >= (y) ? (x) : (y))
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz * A Web proxy module. Stages:
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes * translate_name: set filename to proxy:<URL>
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * can't trust directory_walk/file_walk since these are
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * not in our filesystem. Prevents mod_http from serving
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * the TRACE request we will set aside to handle later.
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
db027b0af55a7fa31f2e1659368d606a8b860bb0chrisd * fix_ups: convert the URL stored in the filename to the
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes * canonical form.
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes * handler: handle proxy requests
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes/* -------------------------------------------------------------- */
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes/* Translate the URL into a 'filename' */
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholesstatic int alias_match(const char *uri, const char *alias_fakename)
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes const char *end_fakename = alias_fakename + strlen(alias_fakename);
2e242dca7111f99d54dd144b7b8418d88d560032chrisd /* any number of '/' in the alias matches any number in
2e242dca7111f99d54dd144b7b8418d88d560032chrisd * the supplied URI, but there must be at least one...
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz /* Other characters are compared literally */
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz /* 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 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;
if (p == NULL)
return HTTP_BAD_REQUEST;
return HTTP_MOVED_PERMANENTLY;
int ii;
#if DEBUGGING
r->uri);
if (!direct_connect) {
return access_status;
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->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;
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;
return NULL;
int timeout;
return NULL;
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;
(request_rec *r), (r),