mod_proxy.h revision 0ad70f568b434ff0d849a00d017751fd3db9b28b
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* Licensed to the Apache Software Foundation (ASF) under one or more
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * contributor license agreements. See the NOTICE file distributed with
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * this work for additional information regarding copyright ownership.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * The ASF licenses this file to You under the Apache License, Version 2.0
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * (the "License"); you may not use this file except in compliance with
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * the License. You may obtain a copy of the License at
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * Unless required by applicable law or agreed to in writing, software
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * distributed under the License is distributed on an "AS IS" BASIS,
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * See the License for the specific language governing permissions and
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * limitations under the License.
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * @brief Proxy Extension Module for Apache
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * @defgroup MOD_PROXY mod_proxy
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * @ingroup APACHE_MODS
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz/* for proxy_canonenc() */
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz enc_path, enc_search, enc_user, enc_fpath, enc_parm
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#else /*APR_CHARSET_EBCDIC*/
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#endif /*APR_CHARSET_EBCDIC*/
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* default Max-Forwards header setting */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* Set this to -1, which complies with RFC2616 by not setting
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * max-forwards if the client didn't send it to us.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulztypedef struct proxy_conn_pool proxy_conn_pool;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulztypedef struct proxy_balancer_method proxy_balancer_method;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* static information about a remote proxy */
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz const char *scheme; /* the schemes handled by this proxy, or '*' */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz const char *protocol; /* the scheme used to talk to this proxy */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz const char *hostname; /* the hostname of this proxy */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz ap_regex_t *regexp; /* compiled regex (if any) for the remote */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz int use_regex; /* simple boolean. True if we have a regex pattern */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz apr_port_t port; /* the port for this proxy */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz unsigned int flags;
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz proxy_balancer *balancer; /* only valid for reverse-proxys */
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz int (*matcher) (struct dirconn_entry * This, request_rec *r);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulztypedef struct {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *workers; /* non-balancer workers, eg ProxyPass http://example.com */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *balancers; /* list of balancers @ config time */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz proxy_worker *forward; /* forward proxy worker */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz proxy_worker *reverse; /* reverse "module-driven" proxy worker */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz const char *domain; /* domain name to use in absence of a domain name in the request */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz const char *id;
9316034585ad46e11b1307ec8289f25b7699d74dEwaryst Schulz apr_pool_t *pool; /* Pool used for allocating this struct */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz int req; /* true if proxy requests are enabled */
9316034585ad46e11b1307ec8289f25b7699d74dEwaryst Schulz int max_balancers; /* maximum number of allowed balancers */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz int bgrowth; /* number of post-config balancers can added */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz } viaopt; /* how to deal with proxy Via: headers */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_global_mutex_t *mutex; /* global lock (needed??) */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_slotmem_instance_t *bslot; /* balancers shm data - runtime */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulztypedef struct {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz const char *p; /* The path */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * ProxyPassReverse and friends are documented as working inside
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * <Location>. But in fact they never have done in the case of
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * more than one <Location>, because the server_conf can't see it.
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * We need to move them to the per-dir config.
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz * Discussed in February 2005:
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz * http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=110726027118798&w=2
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz signed char p_is_fnmatch; /* Is the path an fnmatch candidate? */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * the following setting masks the error page
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * returned from the 'proxied server' and just
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * forwards the status code upwards.
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * This allows the main server (us) to generate
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * the error page, (so it will look like a error
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * returned from the rest of the system
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* if we interpolate env vars per-request, we'll need a per-request
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * copy of the reverse proxy config
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulztypedef struct {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulztypedef struct {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz request_rec *r; /* Request record of the backend request
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * that is used over the backend connection. */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz proxy_worker *worker; /* Connection pool this connection belongs to */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_pool_t *pool; /* Subpool for hostname and addr data */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_sockaddr_t *addr; /* Preparsed remote address info */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_pool_t *scpool; /* Subpool used for socket and connection data */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz void *forward; /* opaque forward proxy data */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int close:1; /* Close 'this' connection */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int need_flush:1; /* Flag to decide whether we need to flush the
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * filter chain or not */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int inreslist:1; /* connection in apr_reslist? */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulztypedef struct {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz float cache_completion; /* completion percentage */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int content_length; /* length of the content */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* Connection pool */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_pool_t *pool; /* The pool used in constructor and destructor calls */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_sockaddr_t *addr; /* Preparsed remote address info */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_reslist_t *res; /* Connection resource list */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz proxy_conn_rec *conn; /* Single connection for prefork mpm */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz/* Keep below in sync with proxy_util.c! */
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz/* worker status bits */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz/* worker status flags */
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst SchulzPROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz/* NOTE: these check the shared status */
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz#define PROXY_WORKER_IS_INITIALIZED(f) ( (f)->s->status & PROXY_WORKER_INITIALIZED )
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz#define PROXY_WORKER_IS_STANDBY(f) ( (f)->s->status & PROXY_WORKER_HOT_STANDBY )
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_WORKER_IS_USABLE(f) ( ( !( (f)->s->status & PROXY_WORKER_NOT_USABLE_BITMAP) ) && \
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define PROXY_WORKER_IS_DRAINING(f) ( (f)->s->status & PROXY_WORKER_DRAIN )
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz/* default worker retry timeout in seconds */
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz/* Some max char string sizes, for shm fields */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_BALANCER_MAX_ROUTE_SIZE PROXY_WORKER_MAX_ROUTE_SIZE
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_BALANCER_MAX_NAME_SIZE PROXY_WORKER_MAX_NAME_SIZE
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_BALANCER_MAX_HOSTNAME_SIZE PROXY_WORKER_MAX_HOSTNAME_SIZE
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_STRNCPY(dst, src) ap_proxy_strncpy((dst), (src), (sizeof(dst)))
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz(w)->s->recv_buffer_size = (c)->recv_buffer_size; \
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz(w)->s->recv_buffer_size_set = (c)->recv_buffer_size_set; \
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz(w)->s->io_buffer_size = (c)->io_buffer_size; \
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz(w)->s->io_buffer_size_set = (c)->io_buffer_size_set; \
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz/* use 2 hashes */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulztypedef struct {
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int def;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz unsigned int fnv;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* Runtime worker status informations. Shared in scoreboard */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulztypedef struct {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz char scheme[PROXY_WORKER_MAX_SCHEME_SIZE]; /* scheme to use ajp|http|https */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz char hostname[PROXY_WORKER_MAX_HOSTNAME_SIZE]; /* remote backend address */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz char route[PROXY_WORKER_MAX_ROUTE_SIZE]; /* balancing route */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz char redirect[PROXY_WORKER_MAX_ROUTE_SIZE]; /* temporary balancing redirection route */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz char flusher[PROXY_WORKER_MAX_SCHEME_SIZE]; /* flush provider used by mod_proxy_fdpass */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int retries; /* number of retries on this worker */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz int min; /* Desired minimum number of available connections */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int smax; /* Soft maximum on the total number of connections */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int hmax; /* Hard maximum on the total number of connections */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int flush_wait; /* poll wait time in microseconds if flush_auto */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz unsigned int status; /* worker status bitfield */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_time_t updated; /* timestamp of last update */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_time_t error_time; /* time of the last error */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_interval_time_t ttl; /* maximum amount of time in seconds a connection
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * may be available while exceeding the soft limit */
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz apr_interval_time_t retry; /* retry interval */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_interval_time_t timeout; /* connection timeout */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_size_t elected; /* Number of times the worker was elected */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_off_t transferred;/* Number of bytes transferred to remote */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_off_t read; /* Number of bytes read from remote */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define ALIGNED_PROXY_WORKER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_worker_shared)))
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz/* Worker configuration */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz unsigned int local_status; /* status of per-process worker */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz proxy_conn_pool *cp; /* Connection pool to use */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz proxy_balancer *balancer; /* which balancer am I in? */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_thread_mutex_t *tmutex; /* Thread lock for updating address cache */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz * Time to wait (in microseconds) to find out if more data is currently
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz * available at the backend.
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulztypedef struct {
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char sticky_path[PROXY_BALANCER_MAX_STICKY_SIZE]; /* URL sticky session identifier */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char sticky[PROXY_BALANCER_MAX_STICKY_SIZE]; /* sticky session identifier */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char lbpname[PROXY_MAX_PROVIDER_NAME_SIZE]; /* lbmethod provider name */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char vhost[PROXY_BALANCER_MAX_HOSTNAME_SIZE];
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_interval_time_t timeout; /* Timeout for waiting on free connection */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz apr_time_t wupdated; /* timestamp of last change to workers list */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz int max_attempts; /* Number of attempts before failing */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int sticky_force:1; /* Disable failover for sticky sessions */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int scolonsep:1; /* true if ';' seps sticky session paths */
struct proxy_balancer {
struct proxy_balancer_method {
request_rec *r);
#define PROXY_THREAD_LOCK(x) ( (x) && (x)->tmutex ? apr_thread_mutex_lock((x)->tmutex) : APR_SUCCESS)
#define PROXY_THREAD_UNLOCK(x) ( (x) && (x)->tmutex ? apr_thread_mutex_unlock((x)->tmutex) : APR_SUCCESS)
#define PROXY_GLOBAL_LOCK(x) ( (x) && (x)->gmutex ? apr_global_mutex_lock((x)->gmutex) : APR_SUCCESS)
#define PROXY_GLOBAL_UNLOCK(x) ( (x) && (x)->gmutex ? apr_global_mutex_unlock((x)->gmutex) : APR_SUCCESS)
#if !defined(WIN32)
#define PROXY_DECLARE_DATA
#define PROXY_DECLARE_DATA
char *url))
request_rec *r,
/* proxy_util.c */
PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, request_rec *);
request_rec *r);
PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *url);
PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *str);
#if !defined(WIN32)
proxy_dir_conf *, const char *);
proxy_dir_conf *, const char *);
proxy_dir_conf *, const char *);
proxy_dir_conf *, const char *);
const char *url);
const char *url,
int do_malloc);
server_rec *s,
apr_pool_t *p);
const char *url,
int careactive);
const char *url);
const char *url,
const char *alias,
int do_malloc);
server_rec *s,
apr_pool_t *p);
* The balancer then rewrites the url to particular worker, like http://host:port
request_rec *r,
char **url);
request_rec *r,
char **url,
const char *proxyname,
char *server_portstr,
int server_portstr_size);
server_rec *s);
server_rec *s);
server_rec *s);
server_rec *s,
int ap_proxy_lb_workers(void);