proxy_http.c revision 700e336393ed1b32cf6f5967dcacb910a22505e9
b66914021bd429f41311d2909a7e9289866da7fdnd/* ====================================================================
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd * The Apache Software License, Version 1.1
b66914021bd429f41311d2909a7e9289866da7fdnd * Copyright (c) 2000 The Apache Software Foundation. All rights
b66914021bd429f41311d2909a7e9289866da7fdnd * reserved.
031b91a62d25106ae69d4693475c79618dd5e884fielding * Redistribution and use in source and binary forms, with or without
031b91a62d25106ae69d4693475c79618dd5e884fielding * modification, are permitted provided that the following conditions
031b91a62d25106ae69d4693475c79618dd5e884fielding * 1. Redistributions of source code must retain the above copyright
b66914021bd429f41311d2909a7e9289866da7fdnd * notice, this list of conditions and the following disclaimer.
b66914021bd429f41311d2909a7e9289866da7fdnd * 2. Redistributions in binary form must reproduce the above copyright
b66914021bd429f41311d2909a7e9289866da7fdnd * notice, this list of conditions and the following disclaimer in
b66914021bd429f41311d2909a7e9289866da7fdnd * the documentation and/or other materials provided with the
b66914021bd429f41311d2909a7e9289866da7fdnd * distribution.
b66914021bd429f41311d2909a7e9289866da7fdnd * 3. The end-user documentation included with the redistribution,
b66914021bd429f41311d2909a7e9289866da7fdnd * if any, must include the following acknowledgment:
b66914021bd429f41311d2909a7e9289866da7fdnd * "This product includes software developed by the
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Apache Software Foundation (http://www.apache.org/)."
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Alternately, this acknowledgment may appear in the software itself,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * if and wherever such third-party acknowledgments normally appear.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * 4. The names "Apache" and "Apache Software Foundation" must
eed2a23d9b5986937f1e2b1c120be97744508a72nd * not be used to endorse or promote products derived from this
eed2a23d9b5986937f1e2b1c120be97744508a72nd * software without prior written permission. For written
eed2a23d9b5986937f1e2b1c120be97744508a72nd * permission, please contact apache@apache.org.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * 5. Products derived from this software may not be called "Apache",
eed2a23d9b5986937f1e2b1c120be97744508a72nd * nor may "Apache" appear in their name, without prior written
eed2a23d9b5986937f1e2b1c120be97744508a72nd * permission of the Apache Software Foundation.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
eed2a23d9b5986937f1e2b1c120be97744508a72nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
eed2a23d9b5986937f1e2b1c120be97744508a72nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
eed2a23d9b5986937f1e2b1c120be97744508a72nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
eed2a23d9b5986937f1e2b1c120be97744508a72nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
eed2a23d9b5986937f1e2b1c120be97744508a72nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
eed2a23d9b5986937f1e2b1c120be97744508a72nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SUCH DAMAGE.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ====================================================================
eed2a23d9b5986937f1e2b1c120be97744508a72nd * This software consists of voluntary contributions made by many
eed2a23d9b5986937f1e2b1c120be97744508a72nd * individuals on behalf of the Apache Software Foundation. For more
eed2a23d9b5986937f1e2b1c120be97744508a72nd * information on the Apache Software Foundation, please see
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Portions of this software are based upon public domain software
eed2a23d9b5986937f1e2b1c120be97744508a72nd * originally written at the National Center for Supercomputing Applications,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * University of Illinois, Urbana-Champaign.
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* HTTP routines for Apache proxy */
f5e4573f2a3ca4b7d7d10bfb50950fa7eff27efbnilgun * Canonicalise http-like URLs.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * scheme is the scheme for the URL
eed2a23d9b5986937f1e2b1c120be97744508a72nd * url is the URL starting with the first '/'
eed2a23d9b5986937f1e2b1c120be97744508a72nd * def_port is the default port for this scheme.
eed2a23d9b5986937f1e2b1c120be97744508a72ndint ap_proxy_http_canon(request_rec *r, char *url, const char *scheme, int def_port)
eed2a23d9b5986937f1e2b1c120be97744508a72nd const char *err;
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd/* do syntatic check.
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd * We break the URL into host, port, path, search
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd/* now parse path/search args, according to rfc1738 */
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd/* N.B. if this isn't a true proxy request, then the URL _path_
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd * has already been decoded. True proxy requests have r->uri
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd * == r->unparsed_uri, and no others have that property.
9ead22080b72dcfbf031f25179e89a7fab346f8and/* process path */
eed2a23d9b5986937f1e2b1c120be97744508a72nd path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, r->proxyreq);
9963f91528694fb21e93da8584c31f226c6de97akess r->filename = apr_pstrcat(r->pool, "proxy:", scheme, "://", host, sport, "/",
eed2a23d9b5986937f1e2b1c120be97744508a72nd path, (search) ? "?" : "", (search) ? search : "", NULL);
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic const char *proxy_location_reverse_map(request_rec *r, const char *url)
eed2a23d9b5986937f1e2b1c120be97744508a72nd conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
eed2a23d9b5986937f1e2b1c120be97744508a72nd/* Clear all connection-based headers from the incoming headers table */
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic void clear_connection(apr_pool_t *p, apr_table_t *headers)
eed2a23d9b5986937f1e2b1c120be97744508a72nd const char *name;
eed2a23d9b5986937f1e2b1c120be97744508a72nd char *next = apr_pstrdup(p, apr_table_get(headers, "Connection"));
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd while (*next) {
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd while (*next && (apr_isspace(*next) || (*next == ','))) {
const char *strp;
char *strp2;
char *desthost;
char *buffer2;
int destport = 0;
char *buf;
ap_bucket *e;
int nocache = 0;
return HTTP_BAD_REQUEST;
desthost = q;
return HTTP_INTERNAL_SERVER_ERROR;
i = ap_get_server_port(r);
if (ap_is_default_port(i,r)) {
e = ap_bucket_create_flush();
if (ap_should_client_block(r)) {
e = ap_bucket_create_flush();
} else if (len == 0) {
AP_BUCKET_REMOVE(e);
minor = 0;
return HTTP_BAD_GATEWAY;
backasswards = 0;
i = ap_get_server_port(r);
if (ap_is_default_port(i,r)) {
if (!r->assbackwards)
ap_proxy_cache_error(&c);
if (backasswards) {
if (!r->header_only) {
return OK;