Commit 40381d67 authored by Mladen Turk's avatar Mladen Turk
Browse files

Add generic reverse proxy worker so that module-driven reverse proxying works....

Add generic reverse proxy worker so that module-driven reverse proxying works. It is enabled by default, but IMO it should be configurable like any other worker so we can limit the number of outgoing connections.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@109316 13f79535-47bb-0310-9956-ffa450edef68
parent 4213522b
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -769,6 +769,7 @@ static void * create_proxy_config(apr_pool_t *p, server_rec *s)
    ps->workers = apr_array_make(p, 10, sizeof(proxy_worker));
    ps->balancers = apr_array_make(p, 10, sizeof(proxy_balancer));
    ps->forward = NULL;
    ps->reverse = NULL;
    ps->domain = NULL;
    ps->viaopt = via_off; /* initially backward compatible with 1.3.1 */
    ps->viaopt_set = 0; /* 0 means default */
@@ -814,6 +815,7 @@ static void * merge_proxy_config(apr_pool_t *p, void *basev, void *overridesv)
    ps->workers = apr_array_append(p, base->workers, overrides->workers);
    ps->balancers = apr_array_append(p, base->balancers, overrides->balancers);
    ps->forward = overrides->forward ? overrides->forward : base->forward;
    ps->reverse = overrides->reverse ? overrides->reverse : base->reverse;

    ps->domain = (overrides->domain == NULL) ? base->domain : overrides->domain;
    ps->viaopt = (overrides->viaopt_set == 0) ? base->viaopt : overrides->viaopt;
@@ -1754,6 +1756,7 @@ static int proxy_status_hook(request_rec *r, int flags)

static void child_init(apr_pool_t *p, server_rec *s)
{
    proxy_worker *reverse = NULL;
    
    while (s) {
        void *sconf = s->module_config;
@@ -1776,6 +1779,17 @@ static void child_init(apr_pool_t *p, server_rec *s)
            /* Do not disable worker in case of errors */
            conf->forward->s->status |= PROXY_WORKER_IGNORE_ERRORS;
        }
        if (!reverse) {
            reverse = ap_proxy_create_worker(p);
            reverse->name     = "proxy:reverse";
            reverse->hostname = "*";
            reverse->scheme   = "*";
            ap_proxy_initialize_worker_share(conf, reverse, s);
            ap_proxy_initialize_worker(reverse, s);
            /* Do not disable worker in case of errors */
            reverse->s->status |= PROXY_WORKER_IGNORE_ERRORS;
        }
        conf->reverse = reverse;
        s = s->next;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ typedef struct {
    apr_array_header_t *workers;
    apr_array_header_t *balancers;
    proxy_worker       *forward;    /* forward proxy worker */
    proxy_worker       *reverse;    /* reverse "module-driven" proxy worker */
    const char *domain;     /* domain name to use in absence of a domain name in the request */
    int req;                /* true if proxy requests are enabled */
    char req_set;
+17 −0
Original line number Diff line number Diff line
@@ -1188,16 +1188,33 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
    if (access_status == DECLINED && *balancer == NULL) {
        *worker = ap_proxy_get_worker(r->pool, conf, *url);
        if (*worker) {
            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                          "proxy: %s: found worker %s for %s",
                           (*worker)->scheme, (*worker)->name, *url);

            *balancer = NULL;
            access_status = OK;
        }
        else if (r->proxyreq == PROXYREQ_PROXY) {
            if (conf->forward) {
                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                              "proxy: *: found forward proxy worker for %s",
                               *url);
                *balancer = NULL;
                *worker = conf->forward;
                access_status = OK;
            }
        }
        else if (r->proxyreq == PROXYREQ_REVERSE) {
            if (conf->reverse) {
                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                              "proxy: *: found reverse proxy worker for %s",
                               *url);
                *balancer = NULL;
                *worker = conf->reverse;
                access_status = OK;
            }
        }
    }
    else if (access_status == DECLINED && balancer != NULL) {
        /* All the workers are busy */