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
47 #include "http_config.h"
48 #include "ap_config.h"
49 #include "http_core.h"
50 #include "http_protocol.h"
51 #include "http_request.h"
52 #include "http_vhost.h"
53 #include "http_main.h"
55 #include "http_connection.h"
56 #include "util_filter.h"
57 #include "util_ebcdic.h"
58 #include "ap_provider.h"
60 #if APR_HAVE_NETINET_IN_H
61 #include <netinet/in.h>
63 #if APR_HAVE_ARPA_INET_H
64 #include <arpa/inet.h>
67 /* for proxy_canonenc() */
69 enc_path, enc_search, enc_user, enc_fpath, enc_parm
72 #if APR_CHARSET_EBCDIC
74 #else /*APR_CHARSET_EBCDIC*/
75 #define CRLF "\015\012"
76 #endif /*APR_CHARSET_EBCDIC*/
78 /* default Max-Forwards header setting */
79 /* Set this to -1, which complies with RFC2616 by not setting
80 * max-forwards if the client didn't send it to us.
82 #define DEFAULT_MAX_FORWARDS -1
84 /* static information about a remote proxy */
86 const char *scheme; /* the schemes handled by this proxy, or '*' */
87 const char *protocol; /* the scheme used to talk to this proxy */
88 const char *hostname; /* the hostname of this proxy */
89 ap_regex_t *regexp; /* compiled regex (if any) for the remote */
90 int use_regex; /* simple boolean. True if we have a regex pattern */
91 apr_port_t port; /* the port for this proxy */
94 #define PROXYPASS_NOCANON 0x01
95 #define PROXYPASS_INTERPOLATE 0x02
103 struct dirconn_entry {
105 struct in_addr addr, mask;
106 struct apr_sockaddr_t *hostaddr;
107 int (*matcher) (struct dirconn_entry * This, request_rec *r);
110 struct noproxy_entry {
112 struct apr_sockaddr_t *addr;
115 typedef struct proxy_balancer proxy_balancer;
116 typedef struct proxy_worker proxy_worker;
117 typedef struct proxy_conn_pool proxy_conn_pool;
118 typedef struct proxy_balancer_method proxy_balancer_method;
121 apr_array_header_t *proxies;
122 apr_array_header_t *sec_proxy;
123 apr_array_header_t *aliases;
124 apr_array_header_t *noproxies;
125 apr_array_header_t *dirconn;
126 apr_array_header_t *workers;
127 apr_array_header_t *balancers;
128 proxy_worker *forward; /* forward proxy worker */
129 proxy_worker *reverse; /* reverse "module-driven" proxy worker */
130 const char *domain; /* domain name to use in absence of a domain name in the request */
131 apr_pool_t *pool; /* Pool used for allocating this struct */
132 int req; /* true if proxy requests are enabled */
138 } viaopt; /* how to deal with proxy Via: headers */
139 apr_size_t recv_buffer_size;
140 apr_size_t io_buffer_size;
142 apr_interval_time_t timeout;
147 } badopt; /* how to deal with bad headers */
152 } proxy_status; /* Status display options */
153 apr_sockaddr_t *source_address;
157 int recv_buffer_size_set:1;
158 int io_buffer_size_set:1;
162 int proxy_status_set:1;
163 int source_address_set:1;
168 const char *p; /* The path */
169 ap_regex_t *r; /* Is this a regex? */
172 * ProxyPassReverse and friends are documented as working inside
173 * <Location>. But in fact they never have done in the case of
174 * more than one <Location>, because the server_conf can't see it.
175 * We need to move them to the per-dir config.
176 * Discussed in February 2005:
177 * http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=110726027118798&w=2
179 apr_array_header_t *raliases;
180 apr_array_header_t* cookie_paths;
181 apr_array_header_t* cookie_domains;
182 const apr_strmatch_pattern* cookie_path_str;
183 const apr_strmatch_pattern* cookie_domain_str;
184 signed char p_is_fnmatch; /* Is the path an fnmatch candidate? */
185 signed char interpolate_env;
186 struct proxy_alias *alias;
189 * the following setting masks the error page
190 * returned from the 'proxied server' and just
191 * forwards the status code upwards.
192 * This allows the main server (us) to generate
193 * the error page, (so it will look like a error
194 * returned from the rest of the system
196 int error_override:1;
198 int preserve_host_set:1;
199 int error_override_set:1;
203 /* if we interpolate env vars per-request, we'll need a per-request
204 * copy of the reverse proxy config
207 apr_array_header_t *raliases;
208 apr_array_header_t* cookie_paths;
209 apr_array_header_t* cookie_domains;
213 conn_rec *connection;
214 request_rec *r; /* Request record of the frontend request
215 * which the backend currently answers. */
216 proxy_worker *worker; /* Connection pool this connection belongs to */
217 apr_pool_t *pool; /* Subpool for hostname and addr data */
218 const char *hostname;
219 apr_sockaddr_t *addr; /* Preparsed remote address info */
220 apr_pool_t *scpool; /* Subpool used for socket and connection data */
221 apr_socket_t *sock; /* Connection socket */
222 void *data; /* per scheme connection data */
223 void *forward; /* opaque forward proxy data */
224 apr_uint32_t flags; /* Connection flags */
227 int close:1; /* Close 'this' connection */
228 int need_flush:1; /* Flag to decide whether we need to flush the
229 * filter chain or not */
231 int inreslist:1; /* connection in apr_reslist? */
233 int cleaned:1; /* connection cleaned? */
237 float cache_completion; /* completion percentage */
238 int content_length; /* length of the content */
241 /* Connection pool */
242 struct proxy_conn_pool {
243 apr_pool_t *pool; /* The pool used in constructor and destructor calls */
244 apr_sockaddr_t *addr; /* Preparsed remote address info */
246 apr_reslist_t *res; /* Connection resource list */
248 proxy_conn_rec *conn; /* Single connection for prefork mpm */
251 /* worker status flags */
252 #define PROXY_WORKER_INITIALIZED 0x0001
253 #define PROXY_WORKER_IGNORE_ERRORS 0x0002
254 #define PROXY_WORKER_DRAIN 0x0004
255 #define PROXY_WORKER_IN_SHUTDOWN 0x0010
256 #define PROXY_WORKER_DISABLED 0x0020
257 #define PROXY_WORKER_STOPPED 0x0040
258 #define PROXY_WORKER_IN_ERROR 0x0080
259 #define PROXY_WORKER_HOT_STANDBY 0x0100
260 #define PROXY_WORKER_FREE 0x0200
262 #define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
263 PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
265 /* NOTE: these check the shared status */
266 #define PROXY_WORKER_IS_INITIALIZED(f) ( (f)->s && \
267 ( (f)->s->status & PROXY_WORKER_INITIALIZED ) )
269 #define PROXY_WORKER_IS_STANDBY(f) ( (f)->s && \
270 ( (f)->s->status & PROXY_WORKER_HOT_STANDBY ) )
272 #define PROXY_WORKER_IS_USABLE(f) ( (f)->s && \
273 ( !( (f)->s->status & PROXY_WORKER_NOT_USABLE_BITMAP) ) && \
274 PROXY_WORKER_IS_INITIALIZED(f) )
276 /* default worker retry timeout in seconds */
277 #define PROXY_WORKER_DEFAULT_RETRY 60
278 #define PROXY_WORKER_MAX_ROUTE_SIZ 63
280 /* Runtime worker status informations. Shared in scoreboard */
282 apr_time_t error_time; /* time of the last error */
284 int retries; /* number of retries on this worker */
285 int lbstatus; /* Current lbstatus */
286 int lbfactor; /* dynamic lbfactor */
287 apr_off_t transferred;/* Number of bytes transferred to remote */
288 apr_off_t read; /* Number of bytes read from remote */
289 apr_size_t elected; /* Number of times the worker was elected */
290 char route[PROXY_WORKER_MAX_ROUTE_SIZ+1];
291 char redirect[PROXY_WORKER_MAX_ROUTE_SIZ+1];
292 void *context; /* general purpose storage */
293 apr_size_t busy; /* busyness factor */
294 int lbset; /* load balancer cluster set */
295 unsigned int apr_hash; /* hash #0 of worker name */
296 unsigned int our_hash; /* hash #1 of worker name. Why 2? hash collisions. */
299 /* Worker configuration */
300 struct proxy_worker {
302 const char *scheme; /* scheme to use ajp|http|https */
303 const char *hostname; /* remote backend address */
304 const char *route; /* balancing route */
305 const char *redirect; /* temporary balancing redirection route */
306 int id; /* scoreboard id */
307 int status; /* temporary worker status */
308 int lbfactor; /* initial load balancing factor */
309 int lbset; /* load balancer cluster set */
310 int min; /* Desired minimum number of available connections */
311 int smax; /* Soft maximum on the total number of connections */
312 int hmax; /* Hard maximum on the total number of connections */
313 apr_interval_time_t ttl; /* maximum amount of time in seconds a connection
314 * may be available while exceeding the soft limit */
315 apr_interval_time_t retry; /* retry interval */
316 apr_interval_time_t timeout; /* connection timeout */
317 apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */
318 apr_interval_time_t ping_timeout;
319 apr_interval_time_t conn_timeout;
320 apr_size_t recv_buffer_size;
321 apr_size_t io_buffer_size;
325 int is_address_reusable:1;
326 proxy_conn_pool *cp; /* Connection pool to use */
327 proxy_worker_stat *s; /* Shared data */
328 void *opaque; /* per scheme worker data */
329 void *context; /* general purpose storage */
334 } flush_packets; /* control AJP flushing */
335 int flush_wait; /* poll wait time in microseconds if flush_auto */
336 const char *flusher; /* flush provider used by mod_proxy_fdpass */
338 apr_thread_mutex_t *mutex; /* Thread lock for updating address cache */
344 int ping_timeout_set:1;
345 int conn_timeout_set:1;
346 int recv_buffer_size_set:1;
347 int io_buffer_size_set:1;
349 int disablereuse_set:1;
350 unsigned int apr_hash; /* hash #0 of worker name */
351 unsigned int our_hash; /* hash #1 of worker name. Why 2? hash collisions. */
355 * Time to wait (in microseconds) to find out if more data is currently
356 * available at the backend.
358 #define PROXY_FLUSH_WAIT 10000
360 struct proxy_balancer {
361 apr_array_header_t *workers; /* array of proxy_workers */
362 const char *name; /* name of the load balancer */
363 apr_interval_time_t timeout; /* Timeout for waiting on free connection */
364 proxy_balancer_method *lbmethod;
366 const char *sticky_path; /* URL sticky session identifier */
367 apr_array_header_t *errstatuses; /* statuses to force members into error */
368 const char *sticky; /* sticky session identifier */
369 int max_attempts; /* Number of attempts before failing */
371 int sticky_force:1; /* Disable failover for sticky sessions */
372 int scolonsep:1; /* true if ';' seps sticky session paths */
373 int max_attempts_set:1;
375 apr_thread_mutex_t *mutex; /* Thread lock for updating lb params */
377 void *context; /* general purpose storage */
378 apr_time_t updated; /* timestamp of last update */
381 struct proxy_balancer_method {
382 const char *name; /* name of the load balancer method*/
383 proxy_worker *(*finder)(proxy_balancer *balancer,
385 void *context; /* general purpose storage */
386 apr_status_t (*reset)(proxy_balancer *balancer, server_rec *s);
387 apr_status_t (*age)(proxy_balancer *balancer, server_rec *s);
388 apr_status_t (*updatelbstatus)(proxy_balancer *balancer, proxy_worker *elected, server_rec *s);
392 #define PROXY_THREAD_LOCK(x) apr_thread_mutex_lock((x)->mutex)
393 #define PROXY_THREAD_UNLOCK(x) apr_thread_mutex_unlock((x)->mutex)
395 #define PROXY_THREAD_LOCK(x) APR_SUCCESS
396 #define PROXY_THREAD_UNLOCK(x) APR_SUCCESS
401 /* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
402 * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
405 #define PROXY_DECLARE(type) type
406 #define PROXY_DECLARE_NONSTD(type) type
407 #define PROXY_DECLARE_DATA
408 #elif defined(PROXY_DECLARE_STATIC)
409 #define PROXY_DECLARE(type) type __stdcall
410 #define PROXY_DECLARE_NONSTD(type) type
411 #define PROXY_DECLARE_DATA
412 #elif defined(PROXY_DECLARE_EXPORT)
413 #define PROXY_DECLARE(type) __declspec(dllexport) type __stdcall
414 #define PROXY_DECLARE_NONSTD(type) __declspec(dllexport) type
415 #define PROXY_DECLARE_DATA __declspec(dllexport)
417 #define PROXY_DECLARE(type) __declspec(dllimport) type __stdcall
418 #define PROXY_DECLARE_NONSTD(type) __declspec(dllimport) type
419 #define PROXY_DECLARE_DATA __declspec(dllimport)
423 * Hook an optional proxy hook. Unlike static hooks, this uses a macro
424 * instead of a function.
426 #define PROXY_OPTIONAL_HOOK(name,fn,pre,succ,order) \
427 APR_OPTIONAL_HOOK(proxy,name,fn,pre,succ,order)
429 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r,
430 proxy_worker *worker, proxy_server_conf *conf, char *url,
431 const char *proxyhost, apr_port_t proxyport))
432 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r,
435 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
436 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r))
440 * It will return the most suitable worker at the moment
441 * and coresponding balancer.
442 * The url is rewritten from balancer://cluster/uri to scheme://host:port/uri
443 * and then the scheme_handler is called.
446 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, pre_request, (proxy_worker **worker,
447 proxy_balancer **balancer,
449 proxy_server_conf *conf, char **url))
452 * It is called after request for updating runtime balancer status.
454 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, post_request, (proxy_worker *worker,
455 proxy_balancer *balancer, request_rec *r,
456 proxy_server_conf *conf))
459 * request status hook
460 * It is called after all proxy processing has been done. This gives other
461 * modules a chance to create default content on failure, for example
463 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, request_status,
464 (int *status, request_rec *r))
468 PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
469 PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
470 PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
471 PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
472 int forcedec, int proxyreq);
473 PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
474 char **passwordp, char **hostp, apr_port_t *port);
475 PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x);
476 PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val);
477 PROXY_DECLARE(char *)ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val);
478 PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x);
479 PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y);
480 PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message);
481 PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
482 PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
483 PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
484 PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
485 PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
486 PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r);
487 PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos);
488 PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key);
489 /* DEPRECATED (will be replaced with ap_proxy_connect_backend */
490 PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, request_rec *);
491 PROXY_DECLARE(apr_status_t) ap_proxy_ssl_connection_cleanup(proxy_conn_rec *conn,
493 PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
494 PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);
495 PROXY_DECLARE(int) ap_proxy_conn_is_https(conn_rec *c);
496 PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
498 /* Header mapping functions, and a typedef of their signature */
499 PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *url);
500 PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *str);
503 typedef const char *(*ap_proxy_header_reverse_map_fn)(request_rec *,
504 proxy_dir_conf *, const char *);
505 #elif defined(PROXY_DECLARE_STATIC)
506 typedef const char *(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
507 proxy_dir_conf *, const char *);
508 #elif defined(PROXY_DECLARE_EXPORT)
509 typedef __declspec(dllexport) const char *
510 (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
511 proxy_dir_conf *, const char *);
513 typedef __declspec(dllimport) const char *
514 (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
515 proxy_dir_conf *, const char *);
519 /* Connection pool API */
521 * Get the worker from proxy configuration
522 * @param p memory pool used for finding worker
523 * @param conf current proxy server configuration
524 * @param url url to find the worker from
525 * @return proxy_worker or NULL if not found
527 PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
528 proxy_server_conf *conf,
531 * Add the worker to proxy configuration
532 * @param worker the new worker
533 * @param p memory pool to allocate worker from
534 * @param conf current proxy server configuration
535 * @param url url containing worker name
536 * @param id slotnumber id or -1 for auto allocation
537 * @return error message or NULL if successful
539 PROXY_DECLARE(const char *) ap_proxy_add_worker_wid(proxy_worker **worker,
541 proxy_server_conf *conf,
546 * Add the worker to proxy configuration
547 * @param worker the new worker
548 * @param p memory pool to allocate worker from
549 * @param conf current proxy server configuration
550 * @param url url containing worker name
551 * @return error message or NULL if successful
553 PROXY_DECLARE(const char *) ap_proxy_add_worker(proxy_worker **worker,
555 proxy_server_conf *conf,
560 * @param p memory pool to allocate worker from
561 * @param id slotnumber id or -1 for auto allocation
564 PROXY_DECLARE(proxy_worker *) ap_proxy_create_worker_wid(apr_pool_t *p, int id);
568 * @param p memory pool to allocate worker from
571 PROXY_DECLARE(proxy_worker *) ap_proxy_create_worker(apr_pool_t *p);
574 * Initialize the worker's shared data
575 * @param conf current proxy server configuration
576 * @param worker worker to initialize
577 * @param s current server record
578 * @param worker worker to initialize
580 PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf,
581 proxy_worker *worker,
586 * Initialize the worker
587 * @param worker worker to initialize
588 * @param s current server record
589 * @param p memory pool used for mutex and connection pool
590 * @return APR_SUCCESS or error code
592 PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker,
596 * Get the balancer from proxy configuration
597 * @param p memory pool used for temporary storage while finding balancer
598 * @param conf current proxy server configuration
599 * @param url url to find the worker from; must have balancer:// prefix
600 * @return proxy_balancer or NULL if not found
602 PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p,
603 proxy_server_conf *conf,
606 * Add the balancer to proxy configuration
607 * @param balancer the new balancer
608 * @param p memory pool to allocate balancer from
609 * @param conf current proxy server configuration
610 * @param url url containing balancer name
611 * @return error message or NULL if successfull
613 PROXY_DECLARE(const char *) ap_proxy_add_balancer(proxy_balancer **balancer,
615 proxy_server_conf *conf,
619 * Add the worker to the balancer
620 * @param pool memory pool for adding worker
621 * @param balancer balancer to add to
622 * @param worker worker to add
623 * @param id slotnumber id or -1 for auto allocation
624 * @note A single worker can be added to multiple balancers.
626 PROXY_DECLARE(void) ap_proxy_add_worker_to_balancer_wid(apr_pool_t *pool,
627 proxy_balancer *balancer,
628 proxy_worker *worker,
631 * Add the worker to the balancer
632 * @param pool memory pool for adding worker
633 * @param balancer balancer to add to
634 * @param worker worker to add
635 * @note A single worker can be added to multiple balancers.
637 PROXY_DECLARE(void) ap_proxy_add_worker_to_balancer(apr_pool_t *pool,
638 proxy_balancer *balancer,
639 proxy_worker *worker);
641 * Get the most suitable worker and/or balancer for the request
642 * @param worker worker used for processing request
643 * @param balancer balancer used for processing request
644 * @param r current request
645 * @param conf current proxy server configuration
646 * @param url request url that balancer can rewrite.
647 * @return OK or HTTP_XXX error
648 * @note It calls balancer pre_request hook if the url starts with balancer://
649 * The balancer then rewrites the url to particular worker, like http://host:port
651 PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
652 proxy_balancer **balancer,
654 proxy_server_conf *conf,
657 * Post request worker and balancer cleanup
658 * @param worker worker used for processing request
659 * @param balancer balancer used for processing request
660 * @param r current request
661 * @param conf current proxy server configuration
662 * @return OK or HTTP_XXX error
663 * @note Whenever the pre_request is called, the post_request has to be
666 PROXY_DECLARE(int) ap_proxy_post_request(proxy_worker *worker,
667 proxy_balancer *balancer,
669 proxy_server_conf *conf);
672 * Request status function
673 * @param status status of proxy request (result)
674 * @param r the request to obtain the status for
675 * @return OK or DECLINED
677 PROXY_DECLARE(int) ap_proxy_request_status(int *status, request_rec *r);
680 * Determine backend hostname and port
681 * @param p memory pool used for processing
682 * @param r current request
683 * @param conf current proxy server configuration
684 * @param worker worker used for processing request
685 * @param conn proxy connection struct
686 * @param uri processed uri
687 * @param url request url
688 * @param proxyname are we connecting directly or via a proxy
689 * @param proxyport proxy host port
690 * @param server_portstr Via headers server port
691 * @param server_portstr_size size of the server_portstr buffer
692 * @return OK or HTTP_XXX error
694 PROXY_DECLARE(int) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
695 proxy_server_conf *conf,
696 proxy_worker *worker,
697 proxy_conn_rec *conn,
700 const char *proxyname,
701 apr_port_t proxyport,
702 char *server_portstr,
703 int server_portstr_size);
706 * Mark a worker for retry
707 * @param proxy_function calling proxy scheme (http, ajp, ...)
708 * @param worker worker used for retrying
709 * @param s current server record
710 * @return OK if marked for retry, DECLINED otherwise
711 * @note The error status of the worker will cleared if the retry interval has
712 * elapsed since the last error.
714 PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function,
715 proxy_worker *worker,
719 * Acquire a connection from worker connection pool
720 * @param proxy_function calling proxy scheme (http, ajp, ...)
721 * @param conn acquired connection
722 * @param worker worker used for obtaining connection
723 * @param s current server record
724 * @return OK or HTTP_XXX error
725 * @note If the connection limit has been reached, the function will
726 * block until a connection becomes available or the timeout has
729 PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
730 proxy_conn_rec **conn,
731 proxy_worker *worker,
734 * Release a connection back to worker connection pool
735 * @param proxy_function calling proxy scheme (http, ajp, ...)
736 * @param conn acquired connection
737 * @param s current server record
738 * @return OK or HTTP_XXX error
739 * @note The connection will be closed if conn->close_on_release is set
741 PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
742 proxy_conn_rec *conn,
745 * Make a connection to the backend
746 * @param proxy_function calling proxy scheme (http, ajp, ...)
747 * @param conn acquired connection
748 * @param worker connection worker
749 * @param s current server record
750 * @return OK or HTTP_XXX error
751 * @note In case the socket already exists for conn, just check the link
754 PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
755 proxy_conn_rec *conn,
756 proxy_worker *worker,
759 * Make a connection record for backend connection
760 * @param proxy_function calling proxy scheme (http, ajp, ...)
761 * @param conn acquired connection
762 * @param c client connection record
763 * @param s current server record
764 * @return OK or HTTP_XXX error
765 * @note The function will return immediately if conn->connection
768 PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
769 proxy_conn_rec *conn,
770 conn_rec *c, server_rec *s);
772 * Signal the upstream chain that the connection to the backend broke in the
773 * middle of the response. This is done by sending an error bucket with
774 * status HTTP_BAD_GATEWAY and an EOS bucket up the filter chain.
775 * @param r current request record of client request
776 * @param brigade The brigade that is sent through the output filter chain
778 PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r,
779 apr_bucket_brigade *brigade);
782 * Return a hash based on the passed string
783 * @param str string to produce hash from
784 * @param method hashing method to use
785 * @return hash as unsigned int
788 typedef enum { PROXY_HASHFUNC_DEFAULT, PROXY_HASHFUNC_APR, PROXY_HASHFUNC_FNV } proxy_hash_t;
790 PROXY_DECLARE(unsigned int)
791 ap_proxy_hashfunc(const char *str, proxy_hash_t method);
793 #define PROXY_LBMETHOD "proxylbmethod"
795 /* The number of dynamic workers that can be added when reconfiguring.
796 * If this limit is reached you must stop and restart the server.
798 #define PROXY_DYNAMIC_BALANCER_LIMIT 16
801 * Calculate maximum number of workers in scoreboard.
802 * @return number of workers to allocate in the scoreboard
804 int ap_proxy_lb_workers(void);
807 extern module PROXY_DECLARE_DATA proxy_module;
809 extern int PROXY_DECLARE_DATA proxy_lb_workers;
811 #endif /*MOD_PROXY_H*/