1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 * @brief Proxy Extension Module for Apache
24 * @defgroup MOD_PROXY mod_proxy
25 * @ingroup APACHE_MODS
29 #include "apr_hooks.h"
32 #include "apr_strings.h"
33 #include "apr_buckets.h"
35 #include "apr_network_io.h"
36 #include "apr_pools.h"
37 #include "apr_strings.h"
40 #include "apr_strmatch.h"
41 #include "apr_fnmatch.h"
42 #include "apr_reslist.h"
43 #define APR_WANT_STRFUNC
46 #include "util_mutex.h"
47 #include "apr_global_mutex.h"
48 #include "apr_thread_mutex.h"
51 #include "http_config.h"
52 #include "ap_config.h"
53 #include "http_core.h"
54 #include "http_protocol.h"
55 #include "http_request.h"
56 #include "http_vhost.h"
57 #include "http_main.h"
59 #include "http_connection.h"
60 #include "util_filter.h"
61 #include "util_ebcdic.h"
62 #include "ap_provider.h"
63 #include "ap_slotmem.h"
65 #if APR_HAVE_NETINET_IN_H
66 #include <netinet/in.h>
68 #if APR_HAVE_ARPA_INET_H
69 #include <arpa/inet.h>
72 /* for proxy_canonenc() */
74 enc_path, enc_search, enc_user, enc_fpath, enc_parm
77 #define BALANCER_PREFIX "balancer://"
79 #if APR_CHARSET_EBCDIC
81 #else /*APR_CHARSET_EBCDIC*/
82 #define CRLF "\015\012"
83 #endif /*APR_CHARSET_EBCDIC*/
85 /* default Max-Forwards header setting */
86 /* Set this to -1, which complies with RFC2616 by not setting
87 * max-forwards if the client didn't send it to us.
89 #define DEFAULT_MAX_FORWARDS -1
91 /* static information about a remote proxy */
93 const char *scheme; /* the schemes handled by this proxy, or '*' */
94 const char *protocol; /* the scheme used to talk to this proxy */
95 const char *hostname; /* the hostname of this proxy */
96 ap_regex_t *regexp; /* compiled regex (if any) for the remote */
97 int use_regex; /* simple boolean. True if we have a regex pattern */
98 apr_port_t port; /* the port for this proxy */
101 #define PROXYPASS_NOCANON 0x01
102 #define PROXYPASS_INTERPOLATE 0x02
110 struct dirconn_entry {
112 struct in_addr addr, mask;
113 struct apr_sockaddr_t *hostaddr;
114 int (*matcher) (struct dirconn_entry * This, request_rec *r);
117 struct noproxy_entry {
119 struct apr_sockaddr_t *addr;
122 typedef struct proxy_balancer proxy_balancer;
123 typedef struct proxy_worker proxy_worker;
124 typedef struct proxy_conn_pool proxy_conn_pool;
125 typedef struct proxy_balancer_method proxy_balancer_method;
128 apr_array_header_t *proxies;
129 apr_array_header_t *sec_proxy;
130 apr_array_header_t *aliases;
131 apr_array_header_t *noproxies;
132 apr_array_header_t *dirconn;
133 apr_array_header_t *workers; /* non-balancer workers, eg ProxyPass http://example.com */
134 apr_array_header_t *balancers; /* list of balancers @ config time */
135 proxy_worker *forward; /* forward proxy worker */
136 proxy_worker *reverse; /* reverse "module-driven" proxy worker */
137 const char *domain; /* domain name to use in absence of a domain name in the request */
139 apr_pool_t *pool; /* Pool used for allocating this struct */
140 int req; /* true if proxy requests are enabled */
146 } viaopt; /* how to deal with proxy Via: headers */
147 apr_size_t recv_buffer_size;
148 apr_size_t io_buffer_size;
150 apr_interval_time_t timeout;
155 } badopt; /* how to deal with bad headers */
160 } proxy_status; /* Status display options */
161 apr_sockaddr_t *source_address;
162 apr_global_mutex_t *mutex; /* global lock (needed??) */
163 ap_slotmem_instance_t *slot; /* balancers shm data - runtime */
167 int recv_buffer_size_set:1;
168 int io_buffer_size_set:1;
172 int proxy_status_set:1;
173 int source_address_set:1;
178 const char *p; /* The path */
179 ap_regex_t *r; /* Is this a regex? */
182 * ProxyPassReverse and friends are documented as working inside
183 * <Location>. But in fact they never have done in the case of
184 * more than one <Location>, because the server_conf can't see it.
185 * We need to move them to the per-dir config.
186 * Discussed in February 2005:
187 * http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=110726027118798&w=2
189 apr_array_header_t *raliases;
190 apr_array_header_t* cookie_paths;
191 apr_array_header_t* cookie_domains;
192 const apr_strmatch_pattern* cookie_path_str;
193 const apr_strmatch_pattern* cookie_domain_str;
194 signed char p_is_fnmatch; /* Is the path an fnmatch candidate? */
195 signed char interpolate_env;
196 struct proxy_alias *alias;
199 * the following setting masks the error page
200 * returned from the 'proxied server' and just
201 * forwards the status code upwards.
202 * This allows the main server (us) to generate
203 * the error page, (so it will look like a error
204 * returned from the rest of the system
206 int error_override:1;
208 int preserve_host_set:1;
209 int error_override_set:1;
211 int add_forwarded_headers:1;
214 /* if we interpolate env vars per-request, we'll need a per-request
215 * copy of the reverse proxy config
218 apr_array_header_t *raliases;
219 apr_array_header_t* cookie_paths;
220 apr_array_header_t* cookie_domains;
224 conn_rec *connection;
225 request_rec *r; /* Request record of the backend request
226 * that is used over the backend connection. */
227 proxy_worker *worker; /* Connection pool this connection belongs to */
228 apr_pool_t *pool; /* Subpool for hostname and addr data */
229 const char *hostname;
230 apr_sockaddr_t *addr; /* Preparsed remote address info */
231 apr_pool_t *scpool; /* Subpool used for socket and connection data */
232 apr_socket_t *sock; /* Connection socket */
233 void *data; /* per scheme connection data */
234 void *forward; /* opaque forward proxy data */
235 apr_uint32_t flags; /* Connection flags */
238 int close:1; /* Close 'this' connection */
239 int need_flush:1; /* Flag to decide whether we need to flush the
240 * filter chain or not */
241 int inreslist:1; /* connection in apr_reslist? */
245 float cache_completion; /* completion percentage */
246 int content_length; /* length of the content */
249 /* Connection pool */
250 struct proxy_conn_pool {
251 apr_pool_t *pool; /* The pool used in constructor and destructor calls */
252 apr_sockaddr_t *addr; /* Preparsed remote address info */
253 apr_reslist_t *res; /* Connection resource list */
254 proxy_conn_rec *conn; /* Single connection for prefork mpm */
257 /* worker status bits */
258 #define PROXY_WORKER_INITIALIZED 0x0001
259 #define PROXY_WORKER_IGNORE_ERRORS 0x0002
260 #define PROXY_WORKER_DRAIN 0x0004
261 #define PROXY_WORKER_IN_SHUTDOWN 0x0010
262 #define PROXY_WORKER_DISABLED 0x0020
263 #define PROXY_WORKER_STOPPED 0x0040
264 #define PROXY_WORKER_IN_ERROR 0x0080
265 #define PROXY_WORKER_HOT_STANDBY 0x0100
266 #define PROXY_WORKER_FREE 0x0200
268 /* worker status flags */
269 #define PROXY_WORKER_INITIALIZED_FLAG 'O'
270 #define PROXY_WORKER_IGNORE_ERRORS_FLAG 'I'
271 #define PROXY_WORKER_DRAIN_FLAG 'N'
272 #define PROXY_WORKER_IN_SHUTDOWN_FLAG 'U'
273 #define PROXY_WORKER_DISABLED_FLAG 'D'
274 #define PROXY_WORKER_STOPPED_FLAG 'S'
275 #define PROXY_WORKER_IN_ERROR_FLAG 'E'
276 #define PROXY_WORKER_HOT_STANDBY_FLAG 'H'
277 #define PROXY_WORKER_FREE_FLAG 'F'
279 #define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
280 PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
282 /* NOTE: these check the shared status */
283 #define PROXY_WORKER_IS_INITIALIZED(f) ( (f)->s->status & PROXY_WORKER_INITIALIZED )
285 #define PROXY_WORKER_IS_STANDBY(f) ( (f)->s->status & PROXY_WORKER_HOT_STANDBY )
287 #define PROXY_WORKER_IS_USABLE(f) ( ( !( (f)->s->status & PROXY_WORKER_NOT_USABLE_BITMAP) ) && \
288 PROXY_WORKER_IS_INITIALIZED(f) )
290 /* default worker retry timeout in seconds */
291 #define PROXY_WORKER_DEFAULT_RETRY 60
293 /* Some max char string sizes, for shm fields */
294 #define PROXY_WORKER_MAX_SCHEME_SIZE 16
295 #define PROXY_WORKER_MAX_ROUTE_SIZE 64
296 #define PROXY_WORKER_MAX_NAME_SIZE 96
297 #define PROXY_BALANCER_MAX_STICKY_SIZE 64
299 #define PROXY_STRNCPY(dst, src) apr_cpystrn((dst), (src), sizeof(dst))
301 /* Runtime worker status informations. Shared in scoreboard */
303 char name[PROXY_WORKER_MAX_NAME_SIZE];
304 char scheme[PROXY_WORKER_MAX_SCHEME_SIZE]; /* scheme to use ajp|http|https */
305 char hostname[PROXY_WORKER_MAX_ROUTE_SIZE]; /* remote backend address */
306 char route[PROXY_WORKER_MAX_ROUTE_SIZE]; /* balancing route */
307 char redirect[PROXY_WORKER_MAX_ROUTE_SIZE]; /* temporary balancing redirection route */
308 char flusher[PROXY_WORKER_MAX_SCHEME_SIZE]; /* flush provider used by mod_proxy_fdpass */
309 int lbset; /* load balancer cluster set */
310 int retries; /* number of retries on this worker */
311 int lbstatus; /* Current lbstatus */
312 int lbfactor; /* dynamic lbfactor */
313 int min; /* Desired minimum number of available connections */
314 int smax; /* Soft maximum on the total number of connections */
315 int hmax; /* Hard maximum on the total number of connections */
316 int flush_wait; /* poll wait time in microseconds if flush_auto */
317 int index; /* shm array index */
318 unsigned int hash; /* hash of worker name */
319 unsigned int status; /* worker status bitfield */
324 } flush_packets; /* control AJP flushing */
325 apr_time_t updated; /* timestamp of last update */
326 apr_time_t error_time; /* time of the last error */
327 apr_interval_time_t ttl; /* maximum amount of time in seconds a connection
328 * may be available while exceeding the soft limit */
329 apr_interval_time_t retry; /* retry interval */
330 apr_interval_time_t timeout; /* connection timeout */
331 apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */
332 apr_interval_time_t ping_timeout;
333 apr_interval_time_t conn_timeout;
334 apr_size_t recv_buffer_size;
335 apr_size_t io_buffer_size;
336 apr_size_t elected; /* Number of times the worker was elected */
337 apr_size_t busy; /* busyness factor */
339 apr_off_t transferred;/* Number of bytes transferred to remote */
340 apr_off_t read; /* Number of bytes read from remote */
341 void *context; /* general purpose storage */
342 unsigned int keepalive:1;
343 unsigned int disablereuse:1;
344 unsigned int is_address_reusable:1;
345 unsigned int retry_set:1;
346 unsigned int timeout_set:1;
347 unsigned int acquire_set:1;
348 unsigned int ping_timeout_set:1;
349 unsigned int conn_timeout_set:1;
350 unsigned int recv_buffer_size_set:1;
351 unsigned int io_buffer_size_set:1;
352 unsigned int keepalive_set:1;
353 unsigned int disablereuse_set:1;
354 unsigned int was_malloced:1;
355 } proxy_worker_shared;
357 #define ALIGNED_PROXY_WORKER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_worker_shared)))
359 /* Worker configuration */
360 struct proxy_worker {
361 unsigned int hash; /* hash of worker name */
362 unsigned int local_status; /* status of per-process worker */
363 proxy_conn_pool *cp; /* Connection pool to use */
364 proxy_worker_shared *s; /* Shared data */
365 proxy_balancer *balancer; /* which balancer am I in? */
366 apr_thread_mutex_t *mutex; /* Thread lock for updating address cache */
367 void *context; /* general purpose storage */
371 * Time to wait (in microseconds) to find out if more data is currently
372 * available at the backend.
374 #define PROXY_FLUSH_WAIT 10000
377 char sticky_path[PROXY_BALANCER_MAX_STICKY_SIZE]; /* URL sticky session identifier */
378 char sticky[PROXY_BALANCER_MAX_STICKY_SIZE]; /* sticky session identifier */
379 char nonce[APR_UUID_FORMATTED_LENGTH + 1];
380 apr_interval_time_t timeout; /* Timeout for waiting on free connection */
381 apr_time_t updated; /* timestamp of last update */
382 proxy_balancer_method *lbmethod;
383 int max_attempts; /* Number of attempts before failing */
384 int index; /* shm array index */
385 int sticky_force:1; /* Disable failover for sticky sessions */
386 int scolonsep:1; /* true if ';' seps sticky session paths */
387 int max_attempts_set:1;
388 unsigned int was_malloced:1;
389 } proxy_balancer_shared;
391 #define ALIGNED_PROXY_BALANCER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_balancer_shared)))
393 struct proxy_balancer {
394 apr_array_header_t *workers; /* initially configured workers */
395 apr_array_header_t *errstatuses; /* statuses to force members into error */
396 ap_slotmem_instance_t *slot; /* worker shm data - runtime */
397 int growth; /* number of post-config workers can added */
398 int max_workers; /* maximum number of allowed workers */
399 const char *name; /* name of the load balancer */
400 const char *sname; /* filesystem safe balancer name */
401 apr_time_t updated; /* timestamp of last update */
402 apr_global_mutex_t *mutex; /* global lock for updating lb params */
403 void *context; /* general purpose storage */
404 proxy_balancer_shared *s; /* Shared data */
407 struct proxy_balancer_method {
408 const char *name; /* name of the load balancer method*/
409 proxy_worker *(*finder)(proxy_balancer *balancer,
411 void *context; /* general purpose storage */
412 apr_status_t (*reset)(proxy_balancer *balancer, server_rec *s);
413 apr_status_t (*age)(proxy_balancer *balancer, server_rec *s);
414 apr_status_t (*updatelbstatus)(proxy_balancer *balancer, proxy_worker *elected, server_rec *s);
417 #define PROXY_THREAD_LOCK(x) apr_thread_mutex_lock((x)->mutex)
418 #define PROXY_THREAD_UNLOCK(x) apr_thread_mutex_unlock((x)->mutex)
420 #define PROXY_GLOBAL_LOCK(x) apr_global_mutex_lock((x)->mutex)
421 #define PROXY_GLOBAL_UNLOCK(x) apr_global_mutex_unlock((x)->mutex)
425 /* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
426 * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
429 #define PROXY_DECLARE(type) type
430 #define PROXY_DECLARE_NONSTD(type) type
431 #define PROXY_DECLARE_DATA
432 #elif defined(PROXY_DECLARE_STATIC)
433 #define PROXY_DECLARE(type) type __stdcall
434 #define PROXY_DECLARE_NONSTD(type) type
435 #define PROXY_DECLARE_DATA
436 #elif defined(PROXY_DECLARE_EXPORT)
437 #define PROXY_DECLARE(type) __declspec(dllexport) type __stdcall
438 #define PROXY_DECLARE_NONSTD(type) __declspec(dllexport) type
439 #define PROXY_DECLARE_DATA __declspec(dllexport)
441 #define PROXY_DECLARE(type) __declspec(dllimport) type __stdcall
442 #define PROXY_DECLARE_NONSTD(type) __declspec(dllimport) type
443 #define PROXY_DECLARE_DATA __declspec(dllimport)
447 * Hook an optional proxy hook. Unlike static hooks, this uses a macro
448 * instead of a function.
450 #define PROXY_OPTIONAL_HOOK(name,fn,pre,succ,order) \
451 APR_OPTIONAL_HOOK(proxy,name,fn,pre,succ,order)
453 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r,
454 proxy_worker *worker, proxy_server_conf *conf, char *url,
455 const char *proxyhost, apr_port_t proxyport))
456 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r,
459 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
460 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r))
464 * It will return the most suitable worker at the moment
465 * and coresponding balancer.
466 * The url is rewritten from balancer://cluster/uri to scheme://host:port/uri
467 * and then the scheme_handler is called.
470 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, pre_request, (proxy_worker **worker,
471 proxy_balancer **balancer,
473 proxy_server_conf *conf, char **url))
476 * It is called after request for updating runtime balancer status.
478 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, post_request, (proxy_worker *worker,
479 proxy_balancer *balancer, request_rec *r,
480 proxy_server_conf *conf))
483 * request status hook
484 * It is called after all proxy processing has been done. This gives other
485 * modules a chance to create default content on failure, for example
487 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, request_status,
488 (int *status, request_rec *r))
492 PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
493 PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
494 PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
495 PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
496 int forcedec, int proxyreq);
497 PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
498 char **passwordp, char **hostp, apr_port_t *port);
499 PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x);
500 PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val);
501 PROXY_DECLARE(char *)ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val);
502 PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x);
503 PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y);
504 PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message);
505 PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
506 PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
507 PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
508 PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
509 PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
510 PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r);
511 PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos);
512 PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key);
513 /* DEPRECATED (will be replaced with ap_proxy_connect_backend */
514 PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, request_rec *);
515 PROXY_DECLARE(apr_status_t) ap_proxy_ssl_connection_cleanup(proxy_conn_rec *conn,
517 PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
518 PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);
519 PROXY_DECLARE(int) ap_proxy_conn_is_https(conn_rec *c);
520 PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
522 /* Header mapping functions, and a typedef of their signature */
523 PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *url);
524 PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *str);
527 typedef const char *(*ap_proxy_header_reverse_map_fn)(request_rec *,
528 proxy_dir_conf *, const char *);
529 #elif defined(PROXY_DECLARE_STATIC)
530 typedef const char *(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
531 proxy_dir_conf *, const char *);
532 #elif defined(PROXY_DECLARE_EXPORT)
533 typedef __declspec(dllexport) const char *
534 (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
535 proxy_dir_conf *, const char *);
537 typedef __declspec(dllimport) const char *
538 (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
539 proxy_dir_conf *, const char *);
543 /* Connection pool API */
545 * Get the worker from proxy configuration
546 * @param p memory pool used for finding worker
547 * @param balancer the balancer that the worker belongs to
548 * @param conf current proxy server configuration
549 * @param url url to find the worker from
550 * @return proxy_worker or NULL if not found
552 PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
553 proxy_balancer *balancer,
554 proxy_server_conf *conf,
557 * Define and Allocate space for the worker to proxy configuration
558 * @param p memory pool to allocate worker from
559 * @param worker the new worker
560 * @param balancer the balancer that the worker belongs to
561 * @param conf current proxy server configuration
562 * @param url url containing worker name
563 * @param do_malloc true if shared struct should be malloced
564 * @return error message or NULL if successful (*worker is new worker)
566 PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
567 proxy_worker **worker,
568 proxy_balancer *balancer,
569 proxy_server_conf *conf,
574 * Share a defined proxy worker via shm
575 * @param worker worker to be shared
576 * @param shm location of shared info
577 * @param i index into shm
578 * @return APR_SUCCESS or error code
580 PROXY_DECLARE(apr_status_t) ap_proxy_share_worker(proxy_worker *worker, proxy_worker_shared *shm, int i);
583 * Initialize the worker by setting up worker connection pool and mutex
584 * @param worker worker to initialize
585 * @param s current server record
586 * @param p memory pool used for mutex and connection pool
587 * @return APR_SUCCESS or error code
589 PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker,
594 * Verifies valid balancer name (eg: balancer://foo)
595 * @param name name to test
596 * @param i number of chars to test; 0 for all.
599 PROXY_DECLARE(int) ap_proxy_valid_balancer_name(char *name, int i);
603 * Get the balancer from proxy configuration
604 * @param p memory pool used for temporary storage while finding balancer
605 * @param conf current proxy server configuration
606 * @param url url to find the worker from; must have balancer:// prefix
607 * @return proxy_balancer or NULL if not found
609 PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p,
610 proxy_server_conf *conf,
614 * Define and Allocate space for the balancer to proxy configuration
615 * @param p memory pool to allocate balancer from
616 * @param balancer the new balancer
617 * @param conf current proxy server configuration
618 * @param url url containing balancer name
619 * @param do_malloc true if shared struct should be malloced
620 * @return error message or NULL if successfull
622 PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p,
623 proxy_balancer **balancer,
624 proxy_server_conf *conf,
629 * Share a defined proxy balancer via shm
630 * @param balancer balancer to be shared
631 * @param shm location of shared info
632 * @param i index into shm
633 * @return APR_SUCCESS or error code
635 PROXY_DECLARE(apr_status_t) ap_proxy_share_balancer(proxy_balancer *balancer,
636 proxy_balancer_shared *shm,
640 * Initialize the balancer as needed
641 * @param balancer balancer to initialize
642 * @param s current server record
643 * @param p memory pool used for mutex and connection pool
644 * @return APR_SUCCESS or error code
646 PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balancer,
651 * Get the most suitable worker and/or balancer for the request
652 * @param worker worker used for processing request
653 * @param balancer balancer used for processing request
654 * @param r current request
655 * @param conf current proxy server configuration
656 * @param url request url that balancer can rewrite.
657 * @return OK or HTTP_XXX error
658 * @note It calls balancer pre_request hook if the url starts with balancer://
659 * The balancer then rewrites the url to particular worker, like http://host:port
661 PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
662 proxy_balancer **balancer,
664 proxy_server_conf *conf,
667 * Post request worker and balancer cleanup
668 * @param worker worker used for processing request
669 * @param balancer balancer used for processing request
670 * @param r current request
671 * @param conf current proxy server configuration
672 * @return OK or HTTP_XXX error
673 * @note Whenever the pre_request is called, the post_request has to be
676 PROXY_DECLARE(int) ap_proxy_post_request(proxy_worker *worker,
677 proxy_balancer *balancer,
679 proxy_server_conf *conf);
682 * Request status function
683 * @param status status of proxy request (result)
684 * @param r the request to obtain the status for
685 * @return OK or DECLINED
687 PROXY_DECLARE(int) ap_proxy_request_status(int *status, request_rec *r);
690 * Determine backend hostname and port
691 * @param p memory pool used for processing
692 * @param r current request
693 * @param conf current proxy server configuration
694 * @param worker worker used for processing request
695 * @param conn proxy connection struct
696 * @param uri processed uri
697 * @param url request url
698 * @param proxyname are we connecting directly or via a proxy
699 * @param proxyport proxy host port
700 * @param server_portstr Via headers server port
701 * @param server_portstr_size size of the server_portstr buffer
702 * @return OK or HTTP_XXX error
704 PROXY_DECLARE(int) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
705 proxy_server_conf *conf,
706 proxy_worker *worker,
707 proxy_conn_rec *conn,
710 const char *proxyname,
711 apr_port_t proxyport,
712 char *server_portstr,
713 int server_portstr_size);
716 * Mark a worker for retry
717 * @param proxy_function calling proxy scheme (http, ajp, ...)
718 * @param worker worker used for retrying
719 * @param s current server record
720 * @return OK if marked for retry, DECLINED otherwise
721 * @note The error status of the worker will cleared if the retry interval has
722 * elapsed since the last error.
724 PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function,
725 proxy_worker *worker,
729 * Acquire a connection from worker connection pool
730 * @param proxy_function calling proxy scheme (http, ajp, ...)
731 * @param conn acquired connection
732 * @param worker worker used for obtaining connection
733 * @param s current server record
734 * @return OK or HTTP_XXX error
735 * @note If the connection limit has been reached, the function will
736 * block until a connection becomes available or the timeout has
739 PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
740 proxy_conn_rec **conn,
741 proxy_worker *worker,
744 * Release a connection back to worker connection pool
745 * @param proxy_function calling proxy scheme (http, ajp, ...)
746 * @param conn acquired connection
747 * @param s current server record
748 * @return OK or HTTP_XXX error
749 * @note The connection will be closed if conn->close_on_release is set
751 PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
752 proxy_conn_rec *conn,
755 * Make a connection to the backend
756 * @param proxy_function calling proxy scheme (http, ajp, ...)
757 * @param conn acquired connection
758 * @param worker connection worker
759 * @param s current server record
760 * @return OK or HTTP_XXX error
761 * @note In case the socket already exists for conn, just check the link
764 PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
765 proxy_conn_rec *conn,
766 proxy_worker *worker,
769 * Make a connection record for backend connection
770 * @param proxy_function calling proxy scheme (http, ajp, ...)
771 * @param conn acquired connection
772 * @param c client connection record
773 * @param s current server record
774 * @return OK or HTTP_XXX error
775 * @note The function will return immediately if conn->connection
778 PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
779 proxy_conn_rec *conn,
780 conn_rec *c, server_rec *s);
782 * Signal the upstream chain that the connection to the backend broke in the
783 * middle of the response. This is done by sending an error bucket with
784 * status HTTP_BAD_GATEWAY and an EOS bucket up the filter chain.
785 * @param r current request record of client request
786 * @param brigade The brigade that is sent through the output filter chain
788 PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r,
789 apr_bucket_brigade *brigade);
792 * Transform buckets from one bucket allocator to another one by creating a
793 * transient bucket for each data bucket and let it use the data read from
794 * the old bucket. Metabuckets are transformed by just recreating them.
795 * Attention: Currently only the following bucket types are handled:
801 * If an other bucket type is found its type is logged as a debug message
802 * and APR_EGENERAL is returned.
803 * @param r current request record of client request. Only used for logging
805 * @param from the brigade that contains the buckets to transform
806 * @param to the brigade that will receive the transformed buckets
807 * @return APR_SUCCESS if all buckets could be transformed APR_EGENERAL
810 PROXY_DECLARE(apr_status_t)
811 ap_proxy_buckets_lifetime_transform(request_rec *r, apr_bucket_brigade *from,
812 apr_bucket_brigade *to);
814 * Return a hash based on the passed string
815 * @param str string to produce hash from
816 * @param method hashing method to use
817 * @return hash as unsigned int
820 typedef enum { PROXY_HASHFUNC_DEFAULT, PROXY_HASHFUNC_APR, PROXY_HASHFUNC_FNV } proxy_hash_t;
822 PROXY_DECLARE(unsigned int) ap_proxy_hashfunc(const char *str, proxy_hash_t method);
826 * Set/unset the worker status bitfield depending on flag
828 * @param set set or unset bit
829 * @param status bitfield to use
830 * @return APR_SUCCESS if valid flag
832 PROXY_DECLARE(apr_status_t) ap_proxy_set_wstatus(char c, int set, unsigned int *status);
834 #define PROXY_LBMETHOD "proxylbmethod"
836 /* The number of dynamic workers that can be added when reconfiguring.
837 * If this limit is reached you must stop and restart the server.
839 #define PROXY_DYNAMIC_BALANCER_LIMIT 16
842 * Calculate maximum number of workers in scoreboard.
843 * @return number of workers to allocate in the scoreboard
845 int ap_proxy_lb_workers(void);
848 extern module PROXY_DECLARE_DATA proxy_module;
850 extern int PROXY_DECLARE_DATA proxy_lb_workers;
852 #endif /*MOD_PROXY_H*/