mod_proxy.c revision 9f22e9ea026e74271ddced44f6d54fa846ddc9bc
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce/* Licensed to the Apache Software Foundation (ASF) under one or more
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * contributor license agreements. See the NOTICE file distributed with
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * this work for additional information regarding copyright ownership.
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * The ASF licenses this file to You under the Apache License, Version 2.0
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * (the "License"); you may not use this file except in compliance with
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * the License. You may obtain a copy of the License at
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * Unless required by applicable law or agreed to in writing, software
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * distributed under the License is distributed on an "AS IS" BASIS,
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * See the License for the specific language governing permissions and
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * limitations under the License.
225d845476b6136be9b77f528ed986bba7a7f732Simo SorceAPR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
79f128801d598ca57a6acebade01136525a47e00Pavel ReichlAPR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
79f128801d598ca57a6acebade01136525a47e00Pavel ReichlAPR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek#define MAX(x,y) ((x) >= (y) ? (x) : (y))
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* return the sizeof of one lb_worker in scoreboard. */
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * A Web proxy module. Stages:
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * translate_name: set filename to proxy:<URL>
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * can't trust directory_walk/file_walk since these are
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * not in our filesystem. Prevents mod_http from serving
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * the TRACE request we will set aside to handle later.
a0d010f488bf15fb3e170ce04092013fa494401fPavel Březina * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * fix_ups: convert the URL stored in the filename to the
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * canonical form.
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * handler: handle proxy requests
b011330c77168cdd864aaae54a75214935136c05Pavel Reichl/* -------------------------------------------------------------- */
b011330c77168cdd864aaae54a75214935136c05Pavel Reichl/* Translate the URL into a 'filename' */
79f128801d598ca57a6acebade01136525a47e00Pavel Reichl (w)->recv_buffer_size = (c)->recv_buffer_size; \
a0d010f488bf15fb3e170ce04092013fa494401fPavel Březina (w)->recv_buffer_size_set = (c)->recv_buffer_size_set; \
a0d010f488bf15fb3e170ce04092013fa494401fPavel Březina (w)->io_buffer_size_set = (c)->io_buffer_size_set; \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovstatic const char *set_worker_param(apr_pool_t *p,
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce const char *key,
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce const char *val)
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce /* Normalized load factor. Used with BalancerMamber,
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * it is a number between 1 and 100.
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce if (worker->lbfactor < 1 || worker->lbfactor > 100)
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce return "LoadFactor must be number between 1..100";
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce /* If set it will give the retry timeout for the worker
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * The default value is 60 seconds, meaning that if
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce * in error state, it will be retried after that timeout.
b011330c77168cdd864aaae54a75214935136c05Pavel Reichl return "Retry must be a positive value";
79f128801d598ca57a6acebade01136525a47e00Pavel Reichl /* Time in seconds that will destroy all the connections
79f128801d598ca57a6acebade01136525a47e00Pavel Reichl * that exceed the smax
a0d010f488bf15fb3e170ce04092013fa494401fPavel Březina return "TTL must be at least one second";
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov /* Initial number of connections to remote
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce return "Min must be a positive number";
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce /* Maximum number of connections to remote
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "Max must be a positive number";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* XXX: More inteligent naming needed */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Maximum number of connections to remote that
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * will not be destroyed
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce return "Smax must be a positive number";
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce /* Acquire timeout in given unit (default is milliseconds).
b011330c77168cdd864aaae54a75214935136c05Pavel Reichl * If set this will be the maximum time to
b011330c77168cdd864aaae54a75214935136c05Pavel Reichl * wait for a free connection.
79f128801d598ca57a6acebade01136525a47e00Pavel Reichl if (ap_timeout_parameter_parse(val, &timeout, "ms") != APR_SUCCESS)
79f128801d598ca57a6acebade01136525a47e00Pavel Reichl return "Acquire timeout has wrong format";
79f128801d598ca57a6acebade01136525a47e00Pavel Reichl return "Acquire must be at least one millisecond";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Connection timeout in seconds.
a0d010f488bf15fb3e170ce04092013fa494401fPavel Březina * Defaults to server timeout.
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce return "Timeout must be at least one second";
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce if (s < 512 && s) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "IOBufferSize must be >= 512 bytes, or 0 for system default.";
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov worker->io_buffer_size = (s ? s : AP_IOBUFSIZE);
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce else if (!strcasecmp(key, "receivebuffersize")) {
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce return "ReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
79f128801d598ca57a6acebade01136525a47e00Pavel Reichl return "KeepAlive must be On|Off";
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce return "DisableReuse must be On|Off";
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce /* Worker route.
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce return "Route length must be < 64 characters";
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce /* Worker redirection route.
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce return "Redirect length must be < 64 characters";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *v;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Worker status.
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek for (v = val; *v; v++) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (*v == '+') {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek else if (*v == '-') {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov worker->status |= PROXY_WORKER_IGNORE_ERRORS;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov return "Unknown status parameter option";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "flushpackets must be on|off|auto";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "flushwait must be <= 1000, or 0 for system default of 10 millseconds.";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek worker->flush_wait = ival * 1000; /* change to microseconds */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Ping/Pong timeout in given unit (default is second).
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (ap_timeout_parameter_parse(val, &timeout, "s") != APR_SUCCESS)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "Ping/Pong timeout has wrong format";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "Ping/Pong timeout must be at least one millisecond";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "lbset must be between 0 and 99";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek else if (!strcasecmp(key, "connectiontimeout")) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Request timeout in given unit (default is second).
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Defaults to connection timeout
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (ap_timeout_parameter_parse(val, &timeout, "s") != APR_SUCCESS)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "Connectiontimeout has wrong format";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "Connectiontimeout must be at least one millisecond.";
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina return "unknown Worker parameter";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozekstatic const char *set_balancer_param(proxy_server_conf *conf,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *key,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov /* Balancer sticky session name.
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Set to something like JSESSIONID or
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * PHPSESSIONID, etc..,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek balancer->sticky = balancer->sticky_path = path;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* If set to 'on' the session will break
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * if the worker is in error state or
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "failover must be On|Off";
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov /* Balancer timeout in seconds.
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * If set this will be the maximum time to
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * wait for a free worker.
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Default is not to wait.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov return "timeout must be at least one second";
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov balancer->timeout = apr_time_from_sec(ival);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Maximum number of failover attempts before
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * giving up.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov return "maximum number of attempts must be a positive number";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek provider = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "unknown lbmethod";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek else if (!strcasecmp(key, "scolonpathdelim")) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* If set to 'on' then ';' will also be
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * used as a session path separator/delim (ala
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina return "scolonpathdelim must be On|Off";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek balancer->errstatuses = apr_array_make(p, 1, sizeof(int));
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina status = apr_strtok(val_split, ", ", &tok_state);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek *(int *)apr_array_push(balancer->errstatuses) = ival;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "erroronstatus must be one or more HTTP response code";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return "unknown Balancer parameter";
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozekstatic int alias_match(const char *uri, const char *alias_fakename)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *end_fakename = alias_fakename + strlen(alias_fakename);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *aliasp = alias_fakename, *urip = uri;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek while (aliasp < end_fakename && urip < end_uri) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* any number of '/' in the alias matches any number in
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina * the supplied URI, but there must be at least one...
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Other characters are compared literally */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* fixup badly encoded stuff (e.g. % as last character) */
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina /* We reach the end of the uri before the end of "alias_fakename"
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek * for example uri is "/" and alias_fakename "/examples"
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Check last alias path component matched all the way */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Return number of characters from URI which matched (may be
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * greater than length of alias, since we may have matched
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * doubled slashes)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* Detect if an absoluteURI should be proxied or not. Note that we
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * have to do this during this phase because later phases are
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * "short-circuiting"... i.e. translate_names will end when the first
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * module returns OK. So for example, if the request is something like:
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * GET http://othervhost/cgi-bin/printenv HTTP/1.0
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * mod_alias will notice the /cgi-bin part and ScriptAlias it and
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina * short-circuit the proxy... just because of the ordering in the
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina * configuration file.
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Ick... msvc (perhaps others) promotes ternary short results to int */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* but it might be something vhosted */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek && !strcasecmp(r->parsed_uri.scheme, ap_http_scheme(r))
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek && ap_matches_request_vhost(r, r->parsed_uri.hostname,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek (apr_port_t)(r->parsed_uri.port_str ? r->parsed_uri.port
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* We need special treatment for CONNECT proxying: it has no scheme part */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek else if (conf->req && r->method_number == M_CONNECT
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozekstatic const char *proxy_interpolate(request_rec *r, const char *str)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Interpolate an env str in a configuration string
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Syntax ${var} --> value_of(var)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Method: replace one var, and recurse on remainder of string
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Nothing clever here, and crap like nested vars may do silly things
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * but we'll at least avoid sending the unwary into a loop
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *end;
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina const char *var;
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina const char *val;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* OK, this is syntax we want to interpolate. Is there such a var ? */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek var = apr_pstrndup(r->pool, start+2, end-(start+2));
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek firstpart = apr_pstrndup(r->pool, str, (start-str));
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozekstatic apr_array_header_t *proxy_vars(request_rec *r,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek apr_array_header_t *ret = apr_array_make(r->pool, hdr->nelts,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek sizeof (struct proxy_alias));
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek struct proxy_alias *old = (struct proxy_alias *) hdr->elts;
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl struct proxy_alias *newcopy = apr_array_push(ret);
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl newcopy->fake = (old[i].flags & PROXYPASS_INTERPOLATE)
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl ? proxy_interpolate(r, old[i].fake) : old[i].fake;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek newcopy->real = (old[i].flags & PROXYPASS_INTERPOLATE)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek ? proxy_interpolate(r, old[i].real) : old[i].real;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek struct proxy_alias *ent = (struct proxy_alias *) conf->aliases->elts;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *fake;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* someone has already set up the proxy, it was possibly ourselves
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * in proxy_detect
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* XXX: since r->uri has been manipulated already we're not really
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * compliant with RFC1945 at this point. But this probably isn't
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * an issue because this is a hybrid proxy/origin server.
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek unsigned int nocanon = ent[i].flags & PROXYPASS_NOCANON;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *use_uri = nocanon ? r->unparsed_uri : r->uri;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (!ap_regexec(ent[i].regex, r->uri, AP_MAX_REG_MATCH, regm, 0)) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* test that we haven't reduced the URI */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (nocanon && ap_regexec(ent[i].regex, r->unparsed_uri,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek found = ap_pregsub(r->pool, real, use_uri, AP_MAX_REG_MATCH,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Note: The strcmp() below catches cases where there
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * was no regex substitution. This is so cases like:
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * ProxyPassMatch \.gif balancer://foo
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * will work "as expected". The upshot is that the 2
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * directives below act the exact same way (ie: $1 is implied):
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * ProxyPassMatch ^(/.*\.gif)$ balancer://foo
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * ProxyPassMatch ^(/.*\.gif)$ balancer://foo$1
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * which may be confusing.
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina found = apr_pstrcat(r->pool, "proxy:", found, NULL);
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina && len != alias_match(r->unparsed_uri, ent[i].fake)) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* We made a reducing transformation, so we can't safely use
115241b0eeedd033d34d9721a896f031140944d7Pavel Březina * unparsed_uri. Safe fallback is to ignore nocanon.
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek "Unescaped URL path matched ProxyPass; ignoring unsafe nocanon");
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* mod_proxy_http needs to be told. Different module. */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek apr_table_setn(r->notes, "proxy-nocanon", "1");
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek proxy_server_conf *sconf = ap_get_module_config(r->server->module_config,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek ap_conf_vector_t *per_dir_defaults = r->server->lookup_defaults;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek ap_conf_vector_t **sec_proxy = (ap_conf_vector_t **) sconf->sec_proxy->elts;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* XXX: shouldn't we use URI here? Canonicalize it first?
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Pass over "proxy:" prefix
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek for (j = 0; j < num_sec; ++j)
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl entry_proxy = ap_get_module_config(entry_config, &proxy_module);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* XXX: What about case insensitive matching ???
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Compare regex, fnmatch or string as appropriate
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * If the entry doesn't relate, then continue
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek ? ap_regexec(entry_proxy->r, proxyname, 0, NULL, 0)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek per_dir_defaults = ap_merge_per_dir_configs(r->pool, per_dir_defaults,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* Don't let the core or mod_http map_to_storage hooks handle this,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * We don't need directory/file_walk, and we want to TRACE on our own.
18f01e63c1968c29bddb9e48c279b583c0444730Jakub Hrozek/* -------------------------------------------------------------- */
18f01e63c1968c29bddb9e48c279b583c0444730Jakub Hrozek/* Fixup the filename */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek * Canonicalise the URL
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* XXX: Shouldn't we try this before we run the proxy_walk? */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if ((dconf->interpolate_env == 1) && (r->proxyreq == PROXYREQ_REVERSE)) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* create per-request copy of reverse proxy conf,
18f01e63c1968c29bddb9e48c279b583c0444730Jakub Hrozek * and interpolate vars in it
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek proxy_req_conf *rconf = apr_palloc(r->pool, sizeof(proxy_req_conf));
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek ap_set_module_config(r->request_config, &proxy_module, rconf);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek rconf->raliases = proxy_vars(r, dconf->raliases);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek rconf->cookie_paths = proxy_vars(r, dconf->cookie_paths);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek rconf->cookie_domains = proxy_vars(r, dconf->cookie_domains);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* canonicalise each specific scheme */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if ((access_status = proxy_run_canon_handler(r, url))) {
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek return OK; /* otherwise; we've done the best we can */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* Send a redirection if the request contains a hostname which is not */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* fully qualified, i.e. doesn't have a domain name appended. Some proxy */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* servers like Netscape's allow this and access hosts from the local */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* domain in this case. I think it is better to redirect to a FQDN, since */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* these will later be found in the bookmarks files. */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* The "ProxyDomain" directive determines what domain will be appended */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozekstatic int proxy_needsdomain(request_rec *r, const char *url, const char *domain)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *ref;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek /* We only want to worry about GETs */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek if (!r->proxyreq || r->method_number != M_GET || !r->parsed_uri.hostname)
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl /* If host does contain a dot already, or it is "localhost", decline */
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl if (strchr(r->parsed_uri.hostname, '.') != NULL /* has domain, or IPv4 literal */
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl || strchr(r->parsed_uri.hostname, ':') != NULL /* IPv6 literal */
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl || strcasecmp(r->parsed_uri.hostname, "localhost") == 0)
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl return DECLINED; /* host name has a dot already */
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl /* Reassemble the request, but insert the domain after the host name */
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl /* Note that the domain name always starts with a dot */
82a958e6592c4a4078e45b7197bbe4751b70f511Pavel Reichl r->parsed_uri.hostname = apr_pstrcat(r->pool, r->parsed_uri.hostname,
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek apr_table_set(r->headers_out, "Location", nuri);
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* -------------------------------------------------------------- */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek/* Invoke handler */
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *p2;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek proxy_server_conf *conf = (proxy_server_conf *)
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek struct proxy_remote *ents = (struct proxy_remote *) proxies->elts;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek const char *str;
c0bca1722d6f9dfb654ad78397be70f79ff39af1Jakub Hrozek struct dirconn_entry *list = (struct dirconn_entry *)conf->dirconn->elts;
225d845476b6136be9b77f528ed986bba7a7f732Simo Sorce /* is this for us? */
return DECLINED;
switch (r->method_number) {
case M_TRACE: {
int access_status;
return OK;
case M_OPTIONS: {
int access_status;
return OK;
if (maxfwd >= 0) {
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 (balancer) {
if (!direct_connect) {
const char *cl_a;
char *end;
goto cleanup;
if (cl_a) {
if (cl > 0) {
goto cleanup;
goto cleanup;
if (balancer) {
if (balancer) {
goto cleanup;
return access_status;
return ps;
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->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;
unsigned int flags = 0;
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;
const char *fake;
const char *real;
const char *interp;
fake = f;
real = r;
interp = i;
real = f;
interp = r;
return NULL;
const char *r, const char *interp)
return NULL;
const char *r, const char *interp)
return NULL;
int found = 0;
if (!found) {
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) {
char *val;
if (!val) {
if (!path)
else if (!name)
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),