Blame SOURCES/httpd-2.4.6-uds.patch

008793
diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c
008793
index 6061e53..75c2a35 100644
008793
--- a/modules/mappers/mod_rewrite.c
008793
+++ b/modules/mappers/mod_rewrite.c
008793
@@ -4120,6 +4120,7 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx)
008793
                     r->filename));
008793
 
008793
         r->filename = apr_pstrcat(r->pool, "proxy:", r->filename, NULL);
008793
+        apr_table_setn(r->notes, "rewrite-proxy", "1");
008793
         return 1;
008793
     }
008793
 
008793
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
008793
index b9d71fa..7f96aff 100644
008793
--- a/modules/proxy/mod_proxy.c
008793
+++ b/modules/proxy/mod_proxy.c
008793
@@ -1348,7 +1348,6 @@ static void *merge_proxy_dir_config(apr_pool_t *p, void *basev, void *addv)
008793
     return new;
008793
 }
008793
 
008793
-
008793
 static const char *
008793
     add_proxy(cmd_parms *cmd, void *dummy, const char *f1, const char *r1, int regex)
008793
 {
008793
@@ -1423,6 +1422,36 @@ static const char *
008793
     return add_proxy(cmd, dummy, f1, r1, 1);
008793
 }
008793
 
008793
+static char *de_socketfy(apr_pool_t *p, char *url)
008793
+{
008793
+    char *ptr;
008793
+    /*
008793
+     * We could be passed a URL during the config stage that contains
008793
+     * the UDS path... ignore it
008793
+     */
008793
+    if (!strncasecmp(url, "unix:", 5) &&
008793
+        ((ptr = ap_strchr(url, '|')) != NULL)) {
008793
+        /* move past the 'unix:...|' UDS path info */
008793
+        char *ret, *c;
008793
+
008793
+        ret = ptr + 1;
008793
+        /* special case: "unix:....|scheme:" is OK, expand
008793
+         * to "unix:....|scheme://localhost"
008793
+         * */
008793
+        c = ap_strchr(ret, ':');
008793
+        if (c == NULL) {
008793
+            return NULL;
008793
+        }
008793
+        if (c[1] == '\0') {
008793
+            return apr_pstrcat(p, ret, "//localhost", NULL);
008793
+        }
008793
+        else {
008793
+            return ret;
008793
+        }
008793
+    }
008793
+    return url;
008793
+}
008793
+
008793
 static const char *
008793
     add_pass(cmd_parms *cmd, void *dummy, const char *arg, int is_regex)
008793
 {
008793
@@ -1514,7 +1543,7 @@ static const char *
008793
     }
008793
 
008793
     new->fake = apr_pstrdup(cmd->pool, f);
008793
-    new->real = apr_pstrdup(cmd->pool, r);
008793
+    new->real = apr_pstrdup(cmd->pool, de_socketfy(cmd->pool, r));
008793
     new->flags = flags;
008793
     if (use_regex) {
008793
         new->regex = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
008793
@@ -1550,26 +1579,41 @@ static const char *
008793
         new->balancer = balancer;
008793
     }
008793
     else {
008793
-        proxy_worker *worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, r);
008793
+        proxy_worker *worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, new->real);
008793
         int reuse = 0;
008793
         if (!worker) {
008793
-            const char *err = ap_proxy_define_worker(cmd->pool, &worker, NULL, conf, r, 0);
008793
+            const char *err;
008793
+            if (use_regex) {
008793
+                err = ap_proxy_define_match_worker(cmd->pool, &worker, NULL,
008793
+                                                   conf, r, 0);
008793
+            }
008793
+            else {
008793
+                err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
008793
+                                             conf, r, 0);
008793
+            }
008793
             if (err)
008793
                 return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
008793
 
008793
             PROXY_COPY_CONF_PARAMS(worker, conf);
008793
-        } else {
008793
+        }
008793
+        else if ((use_regex != 0) ^ (worker->s->is_name_matchable)) {
008793
+            return apr_pstrcat(cmd->temp_pool, "ProxyPass/<Proxy> and "
008793
+                               "ProxyPassMatch/<ProxyMatch> can't be used "
008793
+                               "altogether with the same worker name ",
008793
+                               "(", worker->s->name, ")", NULL);
008793
+        }
008793
+        else {
008793
             reuse = 1;
008793
             ap_log_error(APLOG_MARK, APLOG_INFO, 0, cmd->server, APLOGNO(01145)
008793
                          "Sharing worker '%s' instead of creating new worker '%s'",
008793
-                         worker->s->name, new->real);
008793
+                         ap_proxy_worker_name(cmd->pool, worker), new->real);
008793
         }
008793
 
008793
         for (i = 0; i < arr->nelts; i++) {
008793
             if (reuse) {
008793
                 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(01146)
008793
                              "Ignoring parameter '%s=%s' for worker '%s' because of worker sharing",
008793
-                             elts[i].key, elts[i].val, worker->s->name);
008793
+                             elts[i].key, elts[i].val, ap_proxy_worker_name(cmd->pool, worker));
008793
             } else {
008793
                 const char *err = set_worker_param(cmd->pool, worker, elts[i].key,
008793
                                                    elts[i].val);
008793
@@ -2026,7 +2070,7 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
008793
     }
008793
 
008793
     /* Try to find existing worker */
008793
-    worker = ap_proxy_get_worker(cmd->temp_pool, balancer, conf, name);
008793
+    worker = ap_proxy_get_worker(cmd->temp_pool, balancer, conf, de_socketfy(cmd->temp_pool, name));
008793
     if (!worker) {
008793
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01147)
008793
                      "Defining worker '%s' for balancer '%s'",
008793
@@ -2035,13 +2079,13 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
008793
             return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
008793
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01148)
008793
                      "Defined worker '%s' for balancer '%s'",
008793
-                     worker->s->name, balancer->s->name);
008793
+                     ap_proxy_worker_name(cmd->pool, worker), balancer->s->name);
008793
         PROXY_COPY_CONF_PARAMS(worker, conf);
008793
     } else {
008793
         reuse = 1;
008793
         ap_log_error(APLOG_MARK, APLOG_INFO, 0, cmd->server, APLOGNO(01149)
008793
                      "Sharing worker '%s' instead of creating new worker '%s'",
008793
-                     worker->s->name, name);
008793
+                     ap_proxy_worker_name(cmd->pool, worker), name);
008793
     }
008793
 
008793
     arr = apr_table_elts(params);
008793
@@ -2050,7 +2094,7 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
008793
         if (reuse) {
008793
             ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(01150)
008793
                          "Ignoring parameter '%s=%s' for worker '%s' because of worker sharing",
008793
-                         elts[i].key, elts[i].val, worker->s->name);
008793
+                         elts[i].key, elts[i].val, ap_proxy_worker_name(cmd->pool, worker));
008793
         } else {
008793
             err = set_worker_param(cmd->pool, worker, elts[i].key,
008793
                                                elts[i].val);
008793
@@ -2112,7 +2156,7 @@ static const char *
008793
         }
008793
     }
008793
     else {
008793
-        worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, name);
008793
+        worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, de_socketfy(cmd->temp_pool, name));
008793
         if (!worker) {
008793
             if (in_proxy_section) {
008793
                 err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
008793
@@ -2170,6 +2214,7 @@ static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg)
008793
     char *word, *val;
008793
     proxy_balancer *balancer = NULL;
008793
     proxy_worker *worker = NULL;
008793
+    int use_regex = 0;
008793
 
008793
     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
008793
     proxy_server_conf *sconf =
008793
@@ -2219,6 +2264,7 @@ static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg)
008793
         if (!r) {
008793
             return "Regex could not be compiled";
008793
         }
008793
+        use_regex = 1;
008793
     }
008793
 
008793
     /* initialize our config and fetch it */
008793
@@ -2258,14 +2304,26 @@ static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg)
008793
         }
008793
         else {
008793
             worker = ap_proxy_get_worker(cmd->temp_pool, NULL, sconf,
008793
-                                         conf->p);
008793
+                                         de_socketfy(cmd->temp_pool, (char*)conf->p));
008793
             if (!worker) {
008793
-                err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
008793
-                                          sconf, conf->p, 0);
008793
+                if (use_regex) {
008793
+                    err = ap_proxy_define_match_worker(cmd->pool, &worker, NULL,
008793
+                                                       sconf, conf->p, 0);
008793
+                }
008793
+                else {
008793
+                    err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
008793
+                                                 sconf, conf->p, 0);
008793
+                }
008793
                 if (err)
008793
                     return apr_pstrcat(cmd->temp_pool, thiscmd->name,
008793
                                        " ", err, NULL);
008793
             }
008793
+            else if ((use_regex != 0) ^ (worker->s->is_name_matchable)) {
008793
+                return apr_pstrcat(cmd->temp_pool, "ProxyPass/<Proxy> and "
008793
+                                   "ProxyPassMatch/<ProxyMatch> can't be used "
008793
+                                   "altogether with the same worker name ",
008793
+                                   "(", worker->s->name, ")", NULL);
008793
+            }
008793
         }
008793
         if (worker == NULL && balancer == NULL) {
008793
             return apr_pstrcat(cmd->pool, thiscmd->name,
008793
@@ -2570,6 +2628,8 @@ static void child_init(apr_pool_t *p, server_rec *s)
008793
                 ap_proxy_hashfunc(conf->forward->s->name, PROXY_HASHFUNC_FNV);
008793
             /* Do not disable worker in case of errors */
008793
             conf->forward->s->status |= PROXY_WORKER_IGNORE_ERRORS;
008793
+            /* Mark as the "generic" worker */
008793
+            conf->forward->s->status |= PROXY_WORKER_GENERIC;
008793
             ap_proxy_initialize_worker(conf->forward, s, conf->pool);
008793
             /* Disable address cache for generic forward worker */
008793
             conf->forward->s->is_address_reusable = 0;
008793
@@ -2585,6 +2645,8 @@ static void child_init(apr_pool_t *p, server_rec *s)
008793
                 ap_proxy_hashfunc(reverse->s->name, PROXY_HASHFUNC_FNV);
008793
             /* Do not disable worker in case of errors */
008793
             reverse->s->status |= PROXY_WORKER_IGNORE_ERRORS;
008793
+            /* Mark as the "generic" worker */
008793
+            reverse->s->status |= PROXY_WORKER_GENERIC;
008793
             conf->reverse = reverse;
008793
             ap_proxy_initialize_worker(conf->reverse, s, conf->pool);
008793
             /* Disable address cache for generic reverse worker */
008793
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
008793
index 81fd14c..4fb21c7 100644
008793
--- a/modules/proxy/mod_proxy.h
008793
+++ b/modules/proxy/mod_proxy.h
008793
@@ -249,6 +249,7 @@ typedef struct {
008793
     unsigned int need_flush:1; /* Flag to decide whether we need to flush the
008793
                                 * filter chain or not */
008793
     unsigned int inreslist:1;  /* connection in apr_reslist? */
008793
+    const char   *uds_path;    /* Unix domain socket path */
008793
 } proxy_conn_rec;
008793
 
008793
 typedef struct {
008793
@@ -269,6 +270,7 @@ struct proxy_conn_pool {
008793
 #define PROXY_WORKER_INITIALIZED    0x0001
008793
 #define PROXY_WORKER_IGNORE_ERRORS  0x0002
008793
 #define PROXY_WORKER_DRAIN          0x0004
008793
+#define PROXY_WORKER_GENERIC        0x0008
008793
 #define PROXY_WORKER_IN_SHUTDOWN    0x0010
008793
 #define PROXY_WORKER_DISABLED       0x0020
008793
 #define PROXY_WORKER_STOPPED        0x0040
008793
@@ -280,6 +282,7 @@ struct proxy_conn_pool {
008793
 #define PROXY_WORKER_INITIALIZED_FLAG    'O'
008793
 #define PROXY_WORKER_IGNORE_ERRORS_FLAG  'I'
008793
 #define PROXY_WORKER_DRAIN_FLAG          'N'
008793
+#define PROXY_WORKER_GENERIC_FLAG        'G'
008793
 #define PROXY_WORKER_IN_SHUTDOWN_FLAG    'U'
008793
 #define PROXY_WORKER_DISABLED_FLAG       'D'
008793
 #define PROXY_WORKER_STOPPED_FLAG        'S'
008793
@@ -300,6 +303,8 @@ PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
008793
 
008793
 #define PROXY_WORKER_IS_DRAINING(f)   ( (f)->s->status &  PROXY_WORKER_DRAIN )
008793
 
008793
+#define PROXY_WORKER_IS_GENERIC(f)   ( (f)->s->status &  PROXY_WORKER_GENERIC )
008793
+
008793
 /* default worker retry timeout in seconds */
008793
 #define PROXY_WORKER_DEFAULT_RETRY    60
008793
 
008793
@@ -341,6 +346,7 @@ typedef struct {
008793
     char      route[PROXY_WORKER_MAX_ROUTE_SIZE];     /* balancing route */
008793
     char      redirect[PROXY_WORKER_MAX_ROUTE_SIZE];  /* temporary balancing redirection route */
008793
     char      flusher[PROXY_WORKER_MAX_SCHEME_SIZE];  /* flush provider used by mod_proxy_fdpass */
008793
+    char      uds_path[PROXY_WORKER_MAX_NAME_SIZE];   /* path to worker's unix domain socket if applicable */
008793
     int             lbset;      /* load balancer cluster set */
008793
     int             retries;    /* number of retries on this worker */
008793
     int             lbstatus;   /* Current lbstatus */
008793
@@ -387,6 +393,7 @@ typedef struct {
008793
     unsigned int     keepalive_set:1;
008793
     unsigned int     disablereuse_set:1;
008793
     unsigned int     was_malloced:1;
008793
+    unsigned int     is_name_matchable:1;
008793
 } proxy_worker_shared;
008793
 
008793
 #define ALIGNED_PROXY_WORKER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_worker_shared)))
008793
@@ -586,6 +593,16 @@ typedef __declspec(dllimport) const char *
008793
 
008793
 /* Connection pool API */
008793
 /**
008793
+ * Return the user-land, UDS aware worker name
008793
+ * @param p        memory pool used for displaying worker name
008793
+ * @param worker   the worker
008793
+ * @return         name
008793
+ */
008793
+
008793
+PROXY_DECLARE(char *) ap_proxy_worker_name(apr_pool_t *p,
008793
+                                           proxy_worker *worker);
008793
+
008793
+/**
008793
  * Get the worker from proxy configuration
008793
  * @param p        memory pool used for finding worker
008793
  * @param balancer the balancer that the worker belongs to
008793
@@ -615,6 +632,24 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
008793
                                              int do_malloc);
008793
 
008793
 /**
008793
+ * Define and Allocate space for the ap_strcmp_match()able worker to proxy
008793
+ * configuration.
008793
+ * @param p         memory pool to allocate worker from
008793
+ * @param worker    the new worker
008793
+ * @param balancer  the balancer that the worker belongs to
008793
+ * @param conf      current proxy server configuration
008793
+ * @param url       url containing worker name (produces match pattern)
008793
+ * @param do_malloc true if shared struct should be malloced
008793
+ * @return          error message or NULL if successful (*worker is new worker)
008793
+ */
008793
+PROXY_DECLARE(char *) ap_proxy_define_match_worker(apr_pool_t *p,
008793
+                                             proxy_worker **worker,
008793
+                                             proxy_balancer *balancer,
008793
+                                             proxy_server_conf *conf,
008793
+                                             const char *url,
008793
+                                             int do_malloc);
008793
+
008793
+/**
008793
  * Share a defined proxy worker via shm
008793
  * @param worker  worker to be shared
008793
  * @param shm     location of shared info
008793
@@ -983,6 +1018,13 @@ APR_DECLARE_OPTIONAL_FN(int, ap_proxy_clear_connection,
008793
  */
008793
 int ap_proxy_lb_workers(void);
008793
 
008793
+/**
008793
+ * Return the port number of a known scheme (eg: http -> 80).
008793
+ * @param scheme        scheme to test
008793
+ * @return              port number or 0 if unknown
008793
+ */
008793
+PROXY_DECLARE(apr_port_t) ap_proxy_port_of_scheme(const char *scheme);
008793
+
008793
 extern module PROXY_DECLARE_DATA proxy_module;
008793
 
008793
 #endif /*MOD_PROXY_H*/
008793
diff --git a/modules/proxy/mod_proxy_ajp.c b/modules/proxy/mod_proxy_ajp.c
008793
index 3736156..cf52a7d 100644
008793
--- a/modules/proxy/mod_proxy_ajp.c
008793
+++ b/modules/proxy/mod_proxy_ajp.c
008793
@@ -32,7 +32,7 @@ static int proxy_ajp_canon(request_rec *r, char *url)
008793
     char *host, *path, sport[7];
008793
     char *search = NULL;
008793
     const char *err;
008793
-    apr_port_t port = AJP13_DEF_PORT;
008793
+    apr_port_t port, def_port;
008793
 
008793
     /* ap_port_of_scheme() */
008793
     if (strncasecmp(url, "ajp:", 4) == 0) {
008793
@@ -48,6 +48,8 @@ static int proxy_ajp_canon(request_rec *r, char *url)
008793
      * do syntactic check.
008793
      * We break the URL into host, port, path, search
008793
      */
008793
+    port = def_port = ap_proxy_port_of_scheme("ajp");
008793
+
008793
     err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
008793
     if (err) {
008793
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00867) "error parsing URL %s: %s",
008793
@@ -71,7 +73,10 @@ static int proxy_ajp_canon(request_rec *r, char *url)
008793
     if (path == NULL)
008793
         return HTTP_BAD_REQUEST;
008793
 
008793
-    apr_snprintf(sport, sizeof(sport), ":%d", port);
008793
+    if (port != def_port)
008793
+         apr_snprintf(sport, sizeof(sport), ":%d", port);
008793
+    else
008793
+         sport[0] = '\0';
008793
 
008793
     if (ap_strchr_c(host, ':')) {
008793
         /* if literal IPv6 address */
008793
diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c
008793
index 0f45be7..514b8d8 100644
008793
--- a/modules/proxy/mod_proxy_balancer.c
008793
+++ b/modules/proxy/mod_proxy_balancer.c
008793
@@ -118,7 +118,8 @@ static void init_balancer_members(apr_pool_t *p, server_rec *s,
008793
         int worker_is_initialized;
008793
         proxy_worker *worker = *workers;
008793
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01158)
008793
-                     "Looking at %s -> %s initialized?", balancer->s->name, worker->s->name);
008793
+                     "Looking at %s -> %s initialized?", balancer->s->name,
008793
+                     ap_proxy_worker_name(p, worker));
008793
         worker_is_initialized = PROXY_WORKER_IS_INITIALIZED(worker);
008793
         if (!worker_is_initialized) {
008793
             ap_proxy_initialize_worker(worker, s, p);
008793
@@ -638,10 +639,11 @@ static int proxy_balancer_post_request(proxy_worker *worker,
008793
             int val = ((int *)balancer->errstatuses->elts)[i];
008793
             if (r->status == val) {
008793
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01174)
008793
-                              "%s: Forcing worker (%s) into error state " 
008793
+                              "%s: Forcing worker (%s) into error state "
008793
                               "due to status code %d matching 'failonstatus' "
008793
                               "balancer parameter",
008793
-                              balancer->s->name, worker->s->name, val);
008793
+                              balancer->s->name, ap_proxy_worker_name(r->pool, worker),
008793
+                              val);
008793
                 worker->s->status |= PROXY_WORKER_IN_ERROR;
008793
                 worker->s->error_time = apr_time_now();
008793
                 break;
008793
@@ -654,7 +656,7 @@ static int proxy_balancer_post_request(proxy_worker *worker,
008793
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02460)
008793
                       "%s: Forcing worker (%s) into error state "
008793
                       "due to timeout and 'failonstatus' parameter being set",
008793
-                       balancer->s->name, worker->s->name);
008793
+                       balancer->s->name, ap_proxy_worker_name(r->pool, worker));
008793
         worker->s->status |= PROXY_WORKER_IN_ERROR;
008793
         worker->s->error_time = apr_time_now();
008793
 
008793
@@ -1282,7 +1284,7 @@ static int balancer_handler(request_rec *r)
008793
                 worker = *workers;
008793
                 /* Start proxy_worker */
008793
                 ap_rputs("        <httpd:worker>\n", r);
008793
-                ap_rvputs(r, "          <httpd:name>", worker->s->name,
008793
+                ap_rvputs(r, "          <httpd:name>", ap_proxy_worker_name(r->pool, worker),
008793
                           "</httpd:name>\n", NULL);
008793
                 ap_rvputs(r, "          <httpd:scheme>", worker->s->scheme,
008793
                           "</httpd:scheme>\n", NULL);
008793
@@ -1524,7 +1526,8 @@ static int balancer_handler(request_rec *r)
008793
                           ap_escape_uri(r->pool, worker->s->name),
008793
                           "&nonce=", balancer->s->nonce,
008793
                           "\">", NULL);
008793
-                ap_rvputs(r, worker->s->name, "", NULL);
008793
+                ap_rvputs(r, (*worker->s->uds_path ? "" : ""), ap_proxy_worker_name(r->pool, worker),
008793
+                          (*worker->s->uds_path ? "" : ""), "", NULL);
008793
                 ap_rvputs(r, "", ap_escape_html(r->pool, worker->s->route),
008793
                           NULL);
008793
                 ap_rvputs(r, "",
008793
@@ -1549,7 +1552,7 @@ static int balancer_handler(request_rec *r)
008793
         ap_rputs("
\n", r);
008793
         if (wsel && bsel) {
008793
             ap_rputs("

Edit worker settings for ", r);

008793
-            ap_rvputs(r, wsel->s->name, "\n", NULL);
008793
+            ap_rvputs(r, (*wsel->s->uds_path?"":""), ap_proxy_worker_name(r->pool, wsel), (*wsel->s->uds_path?"":""), "\n", NULL);
008793
             ap_rputs("
008793
             ap_rvputs(r, ap_escape_uri(r->pool, action), "\">\n", NULL);
008793
             ap_rputs("
\n
Load factor:
008793
diff --git a/modules/proxy/mod_proxy_fcgi.c b/modules/proxy/mod_proxy_fcgi.c
008793
index 0f84416..d5ca1fa 100644
008793
--- a/modules/proxy/mod_proxy_fcgi.c
008793
+++ b/modules/proxy/mod_proxy_fcgi.c
008793
@@ -77,7 +77,7 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
008793
 {
008793
     char *host, sport[7];
008793
     const char *err, *path;
008793
-    apr_port_t port = 8000;
008793
+    apr_port_t port, def_port;
008793
 
008793
     if (strncasecmp(url, "fcgi:", 5) == 0) {
008793
         url += 5;
008793
@@ -86,9 +86,10 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
008793
         return DECLINED;
008793
     }
008793
 
008793
+    port = def_port = ap_proxy_port_of_scheme("fcgi");
008793
+
008793
     ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
008793
                  "canonicalising URL %s", url);
008793
-
008793
     err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
008793
     if (err) {
008793
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01059)
008793
@@ -96,7 +97,10 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
008793
         return HTTP_BAD_REQUEST;
008793
     }
008793
 
008793
-    apr_snprintf(sport, sizeof(sport), ":%d", port);
008793
+    if (port != def_port)
008793
+        apr_snprintf(sport, sizeof(sport), ":%d", port);
008793
+    else
008793
+        sport[0] = '\0';
008793
 
008793
     if (ap_strchr_c(host, ':')) {
008793
         /* if literal IPv6 address */
008793
@@ -930,7 +934,7 @@ static int proxy_fcgi_handler(request_rec *r, proxy_worker *worker,
008793
     int status;
008793
     char server_portstr[32];
008793
     conn_rec *origin = NULL;
008793
-    proxy_conn_rec *backend = NULL;
008793
+    proxy_conn_rec *backend;
008793
 
008793
     proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
008793
                                                  &proxy_module);
008793
@@ -943,10 +947,7 @@ static int proxy_fcgi_handler(request_rec *r, proxy_worker *worker,
008793
                   "url: %s proxyname: %s proxyport: %d",
008793
                  url, proxyname, proxyport);
008793
 
008793
-    if (strncasecmp(url, "fcgi:", 5) == 0) {
008793
-        url += 5;
008793
-    }
008793
-    else {
008793
+    if (strncasecmp(url, "fcgi:", 5) != 0) {
008793
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01077) "declining URL %s", url);
008793
         return DECLINED;
008793
     }
008793
@@ -954,16 +955,14 @@ static int proxy_fcgi_handler(request_rec *r, proxy_worker *worker,
008793
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01078) "serving URL %s", url);
008793
 
008793
     /* Create space for state information */
008793
-    if (! backend) {
008793
-        status = ap_proxy_acquire_connection(FCGI_SCHEME, &backend, worker,
008793
-                                             r->server);
008793
-        if (status != OK) {
008793
-            if (backend) {
008793
-                backend->close = 1;
008793
-                ap_proxy_release_connection(FCGI_SCHEME, backend, r->server);
008793
-            }
008793
-            return status;
008793
+    status = ap_proxy_acquire_connection(FCGI_SCHEME, &backend, worker,
008793
+                                         r->server);
008793
+    if (status != OK) {
008793
+        if (backend) {
008793
+            backend->close = 1;
008793
+            ap_proxy_release_connection(FCGI_SCHEME, backend, r->server);
008793
         }
008793
+        return status;
008793
     }
008793
 
008793
     backend->is_ssl = 0;
008793
diff --git a/modules/proxy/mod_proxy_http.c b/modules/proxy/mod_proxy_http.c
008793
index 05f33b4..f0bb0ed 100644
008793
--- a/modules/proxy/mod_proxy_http.c
008793
+++ b/modules/proxy/mod_proxy_http.c
008793
@@ -54,7 +54,7 @@ static int proxy_http_canon(request_rec *r, char *url)
008793
     else {
008793
         return DECLINED;
008793
     }
008793
-    def_port = apr_uri_port_of_scheme(scheme);
008793
+    port = def_port = ap_proxy_port_of_scheme(scheme);
008793
 
008793
     ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
008793
                   "HTTP: canonicalising URL %s", url);
008793
@@ -62,7 +62,6 @@ static int proxy_http_canon(request_rec *r, char *url)
008793
     /* do syntatic check.
008793
      * We break the URL into host, port, path, search
008793
      */
008793
-    port = def_port;
008793
     err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
008793
     if (err) {
008793
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01083)
008793
diff --git a/modules/proxy/mod_proxy_scgi.c b/modules/proxy/mod_proxy_scgi.c
008793
index f77a986..6deae78 100644
008793
--- a/modules/proxy/mod_proxy_scgi.c
008793
+++ b/modules/proxy/mod_proxy_scgi.c
008793
@@ -176,13 +176,15 @@ static int scgi_canon(request_rec *r, char *url)
008793
 {
008793
     char *host, sport[sizeof(":65535")];
008793
     const char *err, *path;
008793
-    apr_port_t port = SCGI_DEFAULT_PORT;
008793
+    apr_port_t port, def_port;
008793
 
008793
     if (strncasecmp(url, SCHEME "://", sizeof(SCHEME) + 2)) {
008793
         return DECLINED;
008793
     }
008793
     url += sizeof(SCHEME); /* Keep slashes */
008793
 
008793
+    port = def_port = SCGI_DEFAULT_PORT;
008793
+
008793
     err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
008793
     if (err) {
008793
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00857)
008793
@@ -190,7 +192,12 @@ static int scgi_canon(request_rec *r, char *url)
008793
         return HTTP_BAD_REQUEST;
008793
     }
008793
 
008793
-    apr_snprintf(sport, sizeof(sport), ":%u", port);
008793
+    if (port != def_port) {
008793
+        apr_snprintf(sport, sizeof(sport), ":%u", port);
008793
+    }
008793
+    else {
008793
+        sport[0] = '\0';
008793
+    }
008793
 
008793
     if (ap_strchr(host, ':')) { /* if literal IPv6 address */
008793
         host = apr_pstrcat(r->pool, "[", host, "]", NULL);
008793
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
008793
index 8bc9fab..dea2b10 100644
008793
--- a/modules/proxy/proxy_util.c
008793
+++ b/modules/proxy/proxy_util.c
008793
@@ -21,6 +21,7 @@
008793
 #include "apr_version.h"
008793
 #include "apr_hash.h"
008793
 #include "proxy_util.h"
008793
+#include "ajp.h"
008793
 
008793
 #if APR_HAVE_UNISTD_H
008793
 #include <unistd.h>         /* for getpid() */
008793
@@ -31,6 +32,13 @@
008793
 #define apr_socket_create apr_socket_create_ex
008793
 #endif
008793
 
008793
+#if APR_HAVE_SYS_UN_H
008793
+#include <sys/un.h>
008793
+#endif
008793
+#if (APR_MAJOR_VERSION < 2)
008793
+#include "apr_support.h"        /* for apr_wait_for_io_or_timeout() */
008793
+#endif
008793
+
008793
 APLOG_USE_MODULE(proxy);
008793
 
008793
 /*
008793
@@ -86,14 +94,20 @@ PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src,
008793
     char *thenil;
008793
     apr_size_t thelen;
008793
 
008793
+    /* special case handling */
008793
+    if (!dlen) {
008793
+        /* XXX: APR_ENOSPACE would be better */
008793
+        return APR_EGENERAL;
008793
+    }
008793
+    if (!src) {
008793
+        *dst = '\0';
008793
+        return APR_SUCCESS;
008793
+    }
008793
     thenil = apr_cpystrn(dst, src, dlen);
008793
     thelen = thenil - dst;
008793
-    /* Assume the typical case is smaller copying into bigger
008793
-       so we have a fast return */
008793
-    if ((thelen < dlen-1) || ((strlen(src)) == thelen)) {
008793
+    if (src[thelen] == '\0') {
008793
         return APR_SUCCESS;
008793
     }
008793
-    /* XXX: APR_ENOSPACE would be better */
008793
     return APR_EGENERAL;
008793
 }
008793
 
008793
@@ -1218,11 +1232,11 @@ PROXY_DECLARE(apr_status_t) ap_proxy_share_balancer(proxy_balancer *balancer,
008793
     } else {
008793
         action = "re-using";
008793
     }
008793
+    balancer->s = shm;
008793
+    balancer->s->index = i;
008793
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02337)
008793
                  "%s shm[%d] (0x%pp) for %s", action, i, (void *)shm,
008793
                  balancer->s->name);
008793
-    balancer->s = shm;
008793
-    balancer->s->index = i;
008793
     /* the below should always succeed */
008793
     lbmethod = ap_lookup_provider(PROXY_LBMETHOD, balancer->s->lbpname, "0");
008793
     if (lbmethod) {
008793
@@ -1356,7 +1370,7 @@ static apr_status_t connection_cleanup(void *theconn)
008793
         ap_log_perror(APLOG_MARK, APLOG_ERR, 0, conn->pool, APLOGNO(00923)
008793
                       "Pooled connection 0x%pp for worker %s has been"
008793
                       " already returned to the connection pool.", conn,
008793
-                      worker->s->name);
008793
+                      ap_proxy_worker_name(conn->pool, worker));
008793
         return APR_SUCCESS;
008793
     }
008793
 
008793
@@ -1480,6 +1494,55 @@ static apr_status_t connection_destructor(void *resource, void *params,
008793
  * WORKER related...
008793
  */
008793
 
008793
+PROXY_DECLARE(char *) ap_proxy_worker_name(apr_pool_t *p,
008793
+                                           proxy_worker *worker)
008793
+{
008793
+    if (!(*worker->s->uds_path) || !p) {
008793
+        /* just in case */
008793
+        return worker->s->name;
008793
+    }
008793
+    return apr_pstrcat(p, "unix:", worker->s->uds_path, "|", worker->s->name, NULL);
008793
+}
008793
+
008793
+/*
008793
+ * Taken from ap_strcmp_match() :
008793
+ * Match = 0, NoMatch = 1, Abort = -1, Inval = -2
008793
+ * Based loosely on sections of wildmat.c by Rich Salz
008793
+ * Hmmm... shouldn't this really go component by component?
008793
+ *
008793
+ * Adds handling of the "\<any>" => "<any>" unescaping.
008793
+ */
008793
+static int ap_proxy_strcmp_ematch(const char *str, const char *expected)
008793
+{
008793
+    apr_size_t x, y;
008793
+
008793
+    for (x = 0, y = 0; expected[y]; ++y, ++x) {
008793
+        if ((!str[x]) && (expected[y] != '$' || !apr_isdigit(expected[y + 1])))
008793
+            return -1;
008793
+        if (expected[y] == '$' && apr_isdigit(expected[y + 1])) {
008793
+            while (expected[y] == '$' && apr_isdigit(expected[y + 1]))
008793
+                y += 2;
008793
+            if (!expected[y])
008793
+                return 0;
008793
+            while (str[x]) {
008793
+                int ret;
008793
+                if ((ret = ap_proxy_strcmp_ematch(&str[x++], &expected[y])) != 1)
008793
+                    return ret;
008793
+            }
008793
+            return -1;
008793
+        }
008793
+        else if (expected[y] == '\\') {
008793
+            /* NUL is an invalid char! */
008793
+            if (!expected[++y])
008793
+                return -2;
008793
+        }
008793
+        if (str[x] != expected[y])
008793
+            return 1;
008793
+    }
008793
+    /* We got all the way through the worker path without a difference */
008793
+    return 0;
008793
+}
008793
+
008793
 PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
008793
                                                   proxy_balancer *balancer,
008793
                                                   proxy_server_conf *conf,
008793
@@ -1495,6 +1558,10 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
008793
     char *url_copy;
008793
     int i;
008793
 
008793
+    if (!url) {
008793
+        return NULL;
008793
+    }
008793
+
008793
     c = ap_strchr_c(url, ':');
008793
     if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') {
008793
         return NULL;
008793
@@ -1536,11 +1603,15 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
008793
             if ( ((worker_name_length = strlen(worker->s->name)) <= url_length)
008793
                 && (worker_name_length >= min_match)
008793
                 && (worker_name_length > max_match)
008793
-                && (strncmp(url_copy, worker->s->name, worker_name_length) == 0) ) {
008793
+                && (worker->s->is_name_matchable
008793
+                    || strncmp(url_copy, worker->s->name,
008793
+                               worker_name_length) == 0)
008793
+                && (!worker->s->is_name_matchable
008793
+                    || ap_proxy_strcmp_ematch(url_copy,
008793
+                                              worker->s->name) == 0) ) {
008793
                 max_worker = worker;
008793
                 max_match = worker_name_length;
008793
             }
008793
-
008793
         }
008793
     } else {
008793
         worker = (proxy_worker *)conf->workers->elts;
008793
@@ -1548,7 +1619,12 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
008793
             if ( ((worker_name_length = strlen(worker->s->name)) <= url_length)
008793
                 && (worker_name_length >= min_match)
008793
                 && (worker_name_length > max_match)
008793
-                && (strncmp(url_copy, worker->s->name, worker_name_length) == 0) ) {
008793
+                && (worker->s->is_name_matchable
008793
+                    || strncmp(url_copy, worker->s->name,
008793
+                               worker_name_length) == 0)
008793
+                && (!worker->s->is_name_matchable
008793
+                    || ap_proxy_strcmp_ematch(url_copy,
008793
+                                              worker->s->name) == 0) ) {
008793
                 max_worker = worker;
008793
                 max_match = worker_name_length;
008793
             }
008793
@@ -1573,20 +1649,47 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
008793
                                              int do_malloc)
008793
 {
008793
     int rv;
008793
-    apr_uri_t uri;
008793
+    apr_uri_t uri, urisock;
008793
     proxy_worker_shared *wshared;
008793
-    char *ptr;
008793
+    char *ptr, *sockpath = NULL;
008793
 
008793
+    /*
008793
+     * Look to see if we are using UDS:
008793
+     * require format: unix:/path/foo/bar.sock|http://ignored/path2/
008793
+     * This results in talking http to the socket at /path/foo/bar.sock
008793
+     */
008793
+    ptr = ap_strchr((char *)url, '|');
008793
+    if (ptr) {
008793
+        *ptr = '\0';
008793
+        rv = apr_uri_parse(p, url, &urisock);
008793
+        if (rv == APR_SUCCESS && !strcasecmp(urisock.scheme, "unix")) {
008793
+            sockpath = ap_runtime_dir_relative(p, urisock.path);;
008793
+            url = ptr+1;    /* so we get the scheme for the uds */
008793
+        }
008793
+        else {
008793
+            *ptr = '|';
008793
+        }
008793
+    }
008793
     rv = apr_uri_parse(p, url, &uri);
008793
 
008793
     if (rv != APR_SUCCESS) {
008793
-        return "Unable to parse URL";
008793
+        return apr_pstrcat(p, "Unable to parse URL: ", url, NULL);
008793
     }
008793
-    if (!uri.hostname || !uri.scheme) {
008793
-        return "URL must be absolute!";
008793
+    if (!uri.scheme) {
008793
+        return apr_pstrcat(p, "URL must be absolute!: ", url, NULL);
008793
+    }
008793
+    /* allow for unix:/path|http: */
008793
+    if (!uri.hostname) {
008793
+        if (sockpath) {
008793
+            uri.hostname = "localhost";
008793
+        }
008793
+        else {
008793
+            return apr_pstrcat(p, "URL must be absolute!: ", url, NULL);
008793
+        }
008793
+    }
008793
+    else {
008793
+        ap_str_tolower(uri.hostname);
008793
     }
008793
-
008793
-    ap_str_tolower(uri.hostname);
008793
     ap_str_tolower(uri.scheme);
008793
     /*
008793
      * Workers can be associated w/ balancers or on their
008793
@@ -1642,6 +1745,16 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
008793
     wshared->hash.def = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_DEFAULT);
008793
     wshared->hash.fnv = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_FNV);
008793
     wshared->was_malloced = (do_malloc != 0);
008793
+    wshared->is_name_matchable = 0;
008793
+    if (sockpath) {
008793
+        if (PROXY_STRNCPY(wshared->uds_path, sockpath) != APR_SUCCESS) {
008793
+            return apr_psprintf(p, "worker uds path (%s) too long", sockpath);
008793
+        }
008793
+
008793
+    }
008793
+    else {
008793
+        *wshared->uds_path = '\0';
008793
+    }
008793
 
008793
     (*worker)->hash = wshared->hash;
008793
     (*worker)->context = NULL;
008793
@@ -1652,6 +1765,24 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
008793
     return NULL;
008793
 }
008793
 
008793
+PROXY_DECLARE(char *) ap_proxy_define_match_worker(apr_pool_t *p,
008793
+                                             proxy_worker **worker,
008793
+                                             proxy_balancer *balancer,
008793
+                                             proxy_server_conf *conf,
008793
+                                             const char *url,
008793
+                                             int do_malloc)
008793
+{
008793
+    char *err;
008793
+
008793
+    err = ap_proxy_define_worker(p, worker, balancer, conf, url, do_malloc);
008793
+    if (err) {
008793
+        return err;
008793
+    }
008793
+
008793
+    (*worker)->s->is_name_matchable = 1;
008793
+    return NULL;
008793
+}
008793
+
008793
 /*
008793
  * Create an already defined worker and free up memory
008793
  */
008793
@@ -1670,12 +1801,18 @@ PROXY_DECLARE(apr_status_t) ap_proxy_share_worker(proxy_worker *worker, proxy_wo
008793
     } else {
008793
         action = "re-using";
008793
     }
008793
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02338)
008793
-                 "%s shm[%d] (0x%pp) for worker: %s", action, i, (void *)shm,
008793
-                 worker->s->name);
008793
-
008793
     worker->s = shm;
008793
     worker->s->index = i;
008793
+    {
008793
+        apr_pool_t *pool;
008793
+        apr_pool_create(&pool, ap_server_conf->process->pool);
008793
+        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02338)
008793
+                     "%s shm[%d] (0x%pp) for worker: %s", action, i, (void *)shm,
008793
+                     ap_proxy_worker_name(pool, worker));
008793
+        if (pool) {
008793
+            apr_pool_destroy(pool);
008793
+        }
008793
+    }
008793
     return APR_SUCCESS;
008793
 }
008793
 
008793
@@ -1687,11 +1824,13 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
008793
     if (worker->s->status & PROXY_WORKER_INITIALIZED) {
008793
         /* The worker is already initialized */
008793
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00924)
008793
-                     "worker %s shared already initialized", worker->s->name);
008793
+                     "worker %s shared already initialized",
008793
+                     ap_proxy_worker_name(p, worker));
008793
     }
008793
     else {
008793
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00925)
008793
-                     "initializing worker %s shared", worker->s->name);
008793
+                     "initializing worker %s shared",
008793
+                     ap_proxy_worker_name(p, worker));
008793
         /* Set default parameters */
008793
         if (!worker->s->retry_set) {
008793
             worker->s->retry = apr_time_from_sec(PROXY_WORKER_DEFAULT_RETRY);
008793
@@ -1727,11 +1866,13 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
008793
     /* What if local is init'ed and shm isn't?? Even possible? */
008793
     if (worker->local_status & PROXY_WORKER_INITIALIZED) {
008793
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00926)
008793
-                     "worker %s local already initialized", worker->s->name);
008793
+                     "worker %s local already initialized",
008793
+                     ap_proxy_worker_name(p, worker));
008793
     }
008793
     else {
008793
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00927)
008793
-                     "initializing worker %s local", worker->s->name);
008793
+                     "initializing worker %s local",
008793
+                     ap_proxy_worker_name(p, worker));
008793
         apr_global_mutex_lock(proxy_mutex);
008793
         /* Now init local worker data */
008793
         if (worker->tmutex == NULL) {
008793
@@ -1853,6 +1994,8 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
008793
         }
008793
         else if (r->proxyreq == PROXYREQ_REVERSE) {
008793
             if (conf->reverse) {
008793
+                char *ptr;
008793
+                char *ptr2;
008793
                 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
008793
                               "*: found reverse proxy worker for %s", *url);
008793
                 *balancer = NULL;
008793
@@ -1864,6 +2007,36 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
008793
                  * regarding the Connection header in the request.
008793
                  */
008793
                 apr_table_setn(r->subprocess_env, "proxy-nokeepalive", "1");
008793
+                /*
008793
+                 * In the case of the generic reverse proxy, we need to see if we
008793
+                 * were passed a UDS url (eg: from mod_proxy) and adjust uds_path
008793
+                 * as required.
008793
+                 *
008793
+                 * NOTE: Here we use a quick note lookup, but we could also
008793
+                 * check to see if r->filename starts with 'proxy:'
008793
+                 */
008793
+                if (apr_table_get(r->notes, "rewrite-proxy") &&
008793
+                    (ptr2 = ap_strcasestr(r->filename, "unix:")) &&
008793
+                    (ptr = ap_strchr(ptr2, '|'))) {
008793
+                    apr_uri_t urisock;
008793
+                    apr_status_t rv;
008793
+                    *ptr = '\0';
008793
+                    rv = apr_uri_parse(r->pool, ptr2, &urisock);
008793
+                    if (rv == APR_SUCCESS) {
008793
+                        char *rurl = ptr+1;
008793
+                        char *sockpath = ap_runtime_dir_relative(r->pool, urisock.path);
008793
+                        apr_table_setn(r->notes, "uds_path", sockpath);
008793
+                        *url = apr_pstrdup(r->pool, rurl); /* so we get the scheme for the uds */
008793
+                        /* r->filename starts w/ "proxy:", so add after that */
008793
+                        memmove(r->filename+6, rurl, strlen(rurl)+1);
008793
+                        ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
008793
+                                      "*: rewrite of url due to UDS(%s): %s (%s)",
008793
+                                      sockpath, *url, r->filename);
008793
+                    }
008793
+                    else {
008793
+                        *ptr = '|';
008793
+                    }
008793
+                }
008793
             }
008793
         }
008793
     }
008793
@@ -2053,6 +2226,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
008793
     int server_port;
008793
     apr_status_t err = APR_SUCCESS;
008793
     apr_status_t uerr = APR_SUCCESS;
008793
+    const char *uds_path;
008793
 
008793
     /*
008793
      * Break up the URL to determine the host to connect to
008793
@@ -2065,7 +2239,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
008793
                                          NULL));
008793
     }
008793
     if (!uri->port) {
008793
-        uri->port = apr_uri_port_of_scheme(uri->scheme);
008793
+        uri->port = ap_proxy_port_of_scheme(uri->scheme);
008793
     }
008793
 
008793
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00944)
008793
@@ -2093,73 +2267,117 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
008793
      *      to check host and port on the conn and be careful about
008793
      *      spilling the cached addr from the worker.
008793
      */
008793
-    if (!conn->hostname || !worker->s->is_address_reusable ||
008793
-        worker->s->disablereuse) {
008793
-        if (proxyname) {
008793
-            conn->hostname = apr_pstrdup(conn->pool, proxyname);
008793
-            conn->port = proxyport;
008793
-            /*
008793
-             * If we have a forward proxy and the protocol is HTTPS,
008793
-             * then we need to prepend a HTTP CONNECT request before
008793
-             * sending our actual HTTPS requests.
008793
-             * Save our real backend data for using it later during HTTP CONNECT.
008793
-             */
008793
-            if (conn->is_ssl) {
008793
-                const char *proxy_auth;
008793
-
008793
-                forward_info *forward = apr_pcalloc(conn->pool, sizeof(forward_info));
008793
-                conn->forward = forward;
008793
-                forward->use_http_connect = 1;
008793
-                forward->target_host = apr_pstrdup(conn->pool, uri->hostname);
008793
-                forward->target_port = uri->port;
008793
-                /* Do we want to pass Proxy-Authorization along?
008793
-                 * If we haven't used it, then YES
008793
-                 * If we have used it then MAYBE: RFC2616 says we MAY propagate it.
008793
-                 * So let's make it configurable by env.
008793
-                 * The logic here is the same used in mod_proxy_http.
008793
-                 */
008793
-                proxy_auth = apr_table_get(r->headers_in, "Proxy-Authorization");
008793
-                if (proxy_auth != NULL &&
008793
-                    proxy_auth[0] != '\0' &&
008793
-                    r->user == NULL && /* we haven't yet authenticated */
008793
-                    apr_table_get(r->subprocess_env, "Proxy-Chain-Auth")) {
008793
-                    forward->proxy_auth = apr_pstrdup(conn->pool, proxy_auth);
008793
-                }
008793
-            }
008793
+    uds_path = (*worker->s->uds_path ? worker->s->uds_path : apr_table_get(r->notes, "uds_path"));
008793
+    if (uds_path) {
008793
+        if (conn->uds_path == NULL) {
008793
+            /* use (*conn)->pool instead of worker->cp->pool to match lifetime */
008793
+            conn->uds_path = apr_pstrdup(conn->pool, uds_path);
008793
         }
008793
-        else {
008793
-            conn->hostname = apr_pstrdup(conn->pool, uri->hostname);
008793
-            conn->port = uri->port;
008793
-        }
008793
-        socket_cleanup(conn);
008793
-        err = apr_sockaddr_info_get(&(conn->addr),
008793
-                                    conn->hostname, APR_UNSPEC,
008793
-                                    conn->port, 0,
008793
-                                    conn->pool);
008793
-    }
008793
-    else if (!worker->cp->addr) {
008793
-        if ((err = PROXY_THREAD_LOCK(worker)) != APR_SUCCESS) {
008793
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, err, r, APLOGNO(00945) "lock");
008793
-            return HTTP_INTERNAL_SERVER_ERROR;
008793
+        if (conn->uds_path) {
008793
+            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02545)
008793
+                         "%s: has determined UDS as %s",
008793
+                         uri->scheme, conn->uds_path);
008793
         }
008793
+        else {
008793
+            /* should never happen */
008793
+            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02546)
008793
+                         "%s: cannot determine UDS (%s)",
008793
+                         uri->scheme, uds_path);
008793
 
008793
+        }
008793
         /*
008793
-         * Worker can have the single constant backend adress.
008793
-         * The single DNS lookup is used once per worker.
008793
-         * If dynamic change is needed then set the addr to NULL
008793
-         * inside dynamic config to force the lookup.
008793
+         * In UDS cases, some structs are NULL. Protect from de-refs
008793
+         * and provide info for logging at the same time.
008793
          */
008793
-        err = apr_sockaddr_info_get(&(worker->cp->addr),
008793
-                                    conn->hostname, APR_UNSPEC,
008793
-                                    conn->port, 0,
008793
-                                    worker->cp->pool);
008793
-        conn->addr = worker->cp->addr;
008793
-        if ((uerr = PROXY_THREAD_UNLOCK(worker)) != APR_SUCCESS) {
008793
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, uerr, r, APLOGNO(00946) "unlock");
008793
+        if (!conn->addr) {
008793
+            apr_sockaddr_t *sa;
008793
+            apr_sockaddr_info_get(&sa, NULL, APR_UNSPEC, 0, 0, conn->pool);
008793
+            conn->addr = sa;
008793
         }
008793
+        conn->hostname = "httpd-UDS";
008793
+        conn->port = 0;
008793
     }
008793
     else {
008793
-        conn->addr = worker->cp->addr;
008793
+        int will_reuse = worker->s->is_address_reusable && !worker->s->disablereuse;
008793
+        if (!conn->hostname || !will_reuse) {
008793
+            if (proxyname) {
008793
+                conn->hostname = apr_pstrdup(conn->pool, proxyname);
008793
+                conn->port = proxyport;
008793
+                /*
008793
+                 * If we have a forward proxy and the protocol is HTTPS,
008793
+                 * then we need to prepend a HTTP CONNECT request before
008793
+                 * sending our actual HTTPS requests.
008793
+                 * Save our real backend data for using it later during HTTP CONNECT.
008793
+                 */
008793
+                if (conn->is_ssl) {
008793
+                    const char *proxy_auth;
008793
+
008793
+                    forward_info *forward = apr_pcalloc(conn->pool, sizeof(forward_info));
008793
+                    conn->forward = forward;
008793
+                    forward->use_http_connect = 1;
008793
+                    forward->target_host = apr_pstrdup(conn->pool, uri->hostname);
008793
+                    forward->target_port = uri->port;
008793
+                    /* Do we want to pass Proxy-Authorization along?
008793
+                     * If we haven't used it, then YES
008793
+                     * If we have used it then MAYBE: RFC2616 says we MAY propagate it.
008793
+                     * So let's make it configurable by env.
008793
+                     * The logic here is the same used in mod_proxy_http.
008793
+                     */
008793
+                    proxy_auth = apr_table_get(r->headers_in, "Proxy-Authorization");
008793
+                    if (proxy_auth != NULL &&
008793
+                        proxy_auth[0] != '\0' &&
008793
+                        r->user == NULL && /* we haven't yet authenticated */
008793
+                        apr_table_get(r->subprocess_env, "Proxy-Chain-Auth")) {
008793
+                        forward->proxy_auth = apr_pstrdup(conn->pool, proxy_auth);
008793
+                    }
008793
+                }
008793
+            }
008793
+            else {
008793
+                conn->hostname = apr_pstrdup(conn->pool, uri->hostname);
008793
+                conn->port = uri->port;
008793
+            }
008793
+            if (!will_reuse) {
008793
+                /*
008793
+                 * Only do a lookup if we should not reuse the backend address.
008793
+                 * Otherwise we will look it up once for the worker.
008793
+                 */
008793
+                err = apr_sockaddr_info_get(&(conn->addr),
008793
+                                            conn->hostname, APR_UNSPEC,
008793
+                                            conn->port, 0,
008793
+                                            conn->pool);
008793
+            }
008793
+            socket_cleanup(conn);
008793
+        }
008793
+        if (will_reuse) {
008793
+            /*
008793
+             * Looking up the backend address for the worker only makes sense if
008793
+             * we can reuse the address.
008793
+             */
008793
+            if (!worker->cp->addr) {
008793
+                if ((err = PROXY_THREAD_LOCK(worker)) != APR_SUCCESS) {
008793
+                    ap_log_rerror(APLOG_MARK, APLOG_ERR, err, r, APLOGNO(00945) "lock");
008793
+                    return HTTP_INTERNAL_SERVER_ERROR;
008793
+                }
008793
+
008793
+                /*
008793
+                 * Worker can have the single constant backend adress.
008793
+                 * The single DNS lookup is used once per worker.
008793
+                 * If dynamic change is needed then set the addr to NULL
008793
+                 * inside dynamic config to force the lookup.
008793
+                 */
008793
+                err = apr_sockaddr_info_get(&(worker->cp->addr),
008793
+                                            conn->hostname, APR_UNSPEC,
008793
+                                            conn->port, 0,
008793
+                                            worker->cp->pool);
008793
+                conn->addr = worker->cp->addr;
008793
+                if ((uerr = PROXY_THREAD_UNLOCK(worker)) != APR_SUCCESS) {
008793
+                    ap_log_rerror(APLOG_MARK, APLOG_ERR, uerr, r, APLOGNO(00946) "unlock");
008793
+                }
008793
+            }
008793
+            else {
008793
+                conn->addr = worker->cp->addr;
008793
+            }
008793
+        }
008793
     }
008793
     /* Close a possible existing socket if we are told to do so */
008793
     if (conn->close) {
008793
@@ -2360,6 +2578,52 @@ static apr_status_t send_http_connect(proxy_conn_rec *backend,
008793
 }
008793
 
008793
 
008793
+#if APR_HAVE_SYS_UN_H
008793
+/* lifted from mod_proxy_fdpass.c; tweaked addrlen in connect() call */
008793
+static apr_status_t socket_connect_un(apr_socket_t *sock,
008793
+                                      struct sockaddr_un *sa)
008793
+{
008793
+    apr_status_t rv;
008793
+    apr_os_sock_t rawsock;
008793
+    apr_interval_time_t t;
008793
+
008793
+    rv = apr_os_sock_get(&rawsock, sock);
008793
+    if (rv != APR_SUCCESS) {
008793
+        return rv;
008793
+    }
008793
+
008793
+    rv = apr_socket_timeout_get(sock, &t);
008793
+    if (rv != APR_SUCCESS) {
008793
+        return rv;
008793
+    }
008793
+
008793
+    do {
008793
+        const socklen_t addrlen = APR_OFFSETOF(struct sockaddr_un, sun_path)
008793
+                                  + strlen(sa->sun_path) + 1;
008793
+        rv = connect(rawsock, (struct sockaddr*)sa, addrlen);
008793
+    } while (rv == -1 && errno == EINTR);
008793
+
008793
+    if ((rv == -1) && (errno == EINPROGRESS || errno == EALREADY)
008793
+        && (t > 0)) {
008793
+#if APR_MAJOR_VERSION < 2
008793
+        rv = apr_wait_for_io_or_timeout(NULL, sock, 0);
008793
+#else
008793
+        rv = apr_socket_wait(sock, APR_WAIT_WRITE);
008793
+#endif
008793
+
008793
+        if (rv != APR_SUCCESS) {
008793
+            return rv;
008793
+        }
008793
+    }
008793
+
008793
+    if (rv == -1 && errno != EISCONN) {
008793
+        return errno;
008793
+    }
008793
+
008793
+    return APR_SUCCESS;
008793
+}
008793
+#endif
008793
+
008793
 PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
008793
                                             proxy_conn_rec *conn,
008793
                                             proxy_worker *worker,
008793
@@ -2384,93 +2648,131 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
008793
                          proxy_function);
008793
         }
008793
     }
008793
-    while (backend_addr && !connected) {
008793
-        if ((rv = apr_socket_create(&newsock, backend_addr->family,
008793
-                                SOCK_STREAM, APR_PROTO_TCP,
008793
-                                conn->scpool)) != APR_SUCCESS) {
008793
-            loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
008793
-            ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00952)
008793
-                         "%s: error creating fam %d socket for target %s",
008793
-                         proxy_function,
008793
-                         backend_addr->family,
008793
-                         worker->s->hostname);
008793
-            /*
008793
-             * this could be an IPv6 address from the DNS but the
008793
-             * local machine won't give us an IPv6 socket; hopefully the
008793
-             * DNS returned an additional address to try
008793
-             */
008793
-            backend_addr = backend_addr->next;
008793
-            continue;
008793
-        }
008793
-        conn->connection = NULL;
008793
+    while ((backend_addr || conn->uds_path) && !connected) {
008793
+#if APR_HAVE_SYS_UN_H
008793
+        if (conn->uds_path)
008793
+        {
008793
+            struct sockaddr_un sa;
008793
 
008793
-        if (worker->s->recv_buffer_size > 0 &&
008793
-            (rv = apr_socket_opt_set(newsock, APR_SO_RCVBUF,
008793
-                                     worker->s->recv_buffer_size))) {
008793
-            ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00953)
008793
-                         "apr_socket_opt_set(SO_RCVBUF): Failed to set "
008793
-                         "ProxyReceiveBufferSize, using default");
008793
-        }
008793
+            rv = apr_socket_create(&newsock, AF_UNIX, SOCK_STREAM, 0,
008793
+                                   conn->scpool);
008793
+            if (rv != APR_SUCCESS) {
008793
+                loglevel = APLOG_ERR;
008793
+                ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(02453)
008793
+                             "%s: error creating Unix domain socket for "
008793
+                             "target %s",
008793
+                             proxy_function,
008793
+                             worker->s->hostname);
008793
+                break;
008793
+            }
008793
+            conn->connection = NULL;
008793
 
008793
-        rv = apr_socket_opt_set(newsock, APR_TCP_NODELAY, 1);
008793
-        if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
008793
-             ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00954)
008793
-                          "apr_socket_opt_set(APR_TCP_NODELAY): "
008793
-                          "Failed to set");
008793
-        }
008793
+            sa.sun_family = AF_UNIX;
008793
+            apr_cpystrn(sa.sun_path, conn->uds_path, sizeof(sa.sun_path));
008793
 
008793
-        /* Set a timeout for connecting to the backend on the socket */
008793
-        if (worker->s->conn_timeout_set) {
008793
-            apr_socket_timeout_set(newsock, worker->s->conn_timeout);
008793
-        }
008793
-        else if (worker->s->timeout_set) {
008793
-            apr_socket_timeout_set(newsock, worker->s->timeout);
008793
-        }
008793
-        else if (conf->timeout_set) {
008793
-            apr_socket_timeout_set(newsock, conf->timeout);
008793
-        }
008793
-        else {
008793
-             apr_socket_timeout_set(newsock, s->timeout);
008793
-        }
008793
-        /* Set a keepalive option */
008793
-        if (worker->s->keepalive) {
008793
-            if ((rv = apr_socket_opt_set(newsock,
008793
-                            APR_SO_KEEPALIVE, 1)) != APR_SUCCESS) {
008793
-                ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00955)
008793
-                             "apr_socket_opt_set(SO_KEEPALIVE): Failed to set"
008793
-                             " Keepalive");
008793
+            rv = socket_connect_un(newsock, &sa);
008793
+            if (rv != APR_SUCCESS) {
008793
+                apr_socket_close(newsock);
008793
+                ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(02454)
008793
+                             "%s: attempt to connect to Unix domain socket "
008793
+                             "%s (%s) failed",
008793
+                             proxy_function,
008793
+                             conn->uds_path,
008793
+                             worker->s->hostname);
008793
+                break;
008793
             }
008793
         }
008793
-        ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, s,
008793
-                     "%s: fam %d socket created to connect to %s",
008793
-                     proxy_function, backend_addr->family, worker->s->hostname);
008793
+        else
008793
+#endif
008793
+        {
008793
+            if ((rv = apr_socket_create(&newsock, backend_addr->family,
008793
+                                        SOCK_STREAM, APR_PROTO_TCP,
008793
+                                        conn->scpool)) != APR_SUCCESS) {
008793
+                loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
008793
+                ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00952)
008793
+                             "%s: error creating fam %d socket for "
008793
+                             "target %s",
008793
+                             proxy_function,
008793
+                             backend_addr->family,
008793
+                             worker->s->hostname);
008793
+                /*
008793
+                 * this could be an IPv6 address from the DNS but the
008793
+                 * local machine won't give us an IPv6 socket; hopefully the
008793
+                 * DNS returned an additional address to try
008793
+                 */
008793
+                backend_addr = backend_addr->next;
008793
+                continue;
008793
+            }
008793
+            conn->connection = NULL;
008793
+
008793
+            if (worker->s->recv_buffer_size > 0 &&
008793
+                (rv = apr_socket_opt_set(newsock, APR_SO_RCVBUF,
008793
+                                         worker->s->recv_buffer_size))) {
008793
+                ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00953)
008793
+                             "apr_socket_opt_set(SO_RCVBUF): Failed to set "
008793
+                             "ProxyReceiveBufferSize, using default");
008793
+            }
008793
 
008793
-        if (conf->source_address_set) {
008793
-            local_addr = apr_pmemdup(conn->pool, conf->source_address,
008793
-                                     sizeof(apr_sockaddr_t));
008793
-            local_addr->pool = conn->pool;
008793
-            rv = apr_socket_bind(newsock, local_addr);
008793
-            if (rv != APR_SUCCESS) {
008793
-                ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00956)
008793
-                    "%s: failed to bind socket to local address",
008793
-                    proxy_function);
008793
+            rv = apr_socket_opt_set(newsock, APR_TCP_NODELAY, 1);
008793
+            if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
008793
+                ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00954)
008793
+                             "apr_socket_opt_set(APR_TCP_NODELAY): "
008793
+                             "Failed to set");
008793
             }
008793
-        }
008793
 
008793
-        /* make the connection out of the socket */
008793
-        rv = apr_socket_connect(newsock, backend_addr);
008793
+            /* Set a timeout for connecting to the backend on the socket */
008793
+            if (worker->s->conn_timeout_set) {
008793
+                apr_socket_timeout_set(newsock, worker->s->conn_timeout);
008793
+            }
008793
+            else if (worker->s->timeout_set) {
008793
+                apr_socket_timeout_set(newsock, worker->s->timeout);
008793
+            }
008793
+            else if (conf->timeout_set) {
008793
+                apr_socket_timeout_set(newsock, conf->timeout);
008793
+            }
008793
+            else {
008793
+                apr_socket_timeout_set(newsock, s->timeout);
008793
+            }
008793
+            /* Set a keepalive option */
008793
+            if (worker->s->keepalive) {
008793
+                if ((rv = apr_socket_opt_set(newsock,
008793
+                                             APR_SO_KEEPALIVE, 1)) != APR_SUCCESS) {
008793
+                    ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00955)
008793
+                                 "apr_socket_opt_set(SO_KEEPALIVE): Failed to set"
008793
+                                 " Keepalive");
008793
+                }
008793
+            }
008793
+            ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, s,
008793
+                         "%s: fam %d socket created to connect to %s",
008793
+                         proxy_function, backend_addr->family, worker->s->hostname);
008793
+
008793
+            if (conf->source_address_set) {
008793
+                local_addr = apr_pmemdup(conn->pool, conf->source_address,
008793
+                                         sizeof(apr_sockaddr_t));
008793
+                local_addr->pool = conn->pool;
008793
+                rv = apr_socket_bind(newsock, local_addr);
008793
+                if (rv != APR_SUCCESS) {
008793
+                    ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00956)
008793
+                                 "%s: failed to bind socket to local address",
008793
+                                 proxy_function);
008793
+                }
008793
+            }
008793
 
008793
-        /* if an error occurred, loop round and try again */
008793
-        if (rv != APR_SUCCESS) {
008793
-            apr_socket_close(newsock);
008793
-            loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
008793
-            ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00957)
008793
-                         "%s: attempt to connect to %pI (%s) failed",
008793
-                         proxy_function,
008793
-                         backend_addr,
008793
-                         worker->s->hostname);
008793
-            backend_addr = backend_addr->next;
008793
-            continue;
008793
+            /* make the connection out of the socket */
008793
+            rv = apr_socket_connect(newsock, backend_addr);
008793
+
008793
+            /* if an error occurred, loop round and try again */
008793
+            if (rv != APR_SUCCESS) {
008793
+                apr_socket_close(newsock);
008793
+                loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
008793
+                ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00957)
008793
+                             "%s: attempt to connect to %pI (%s) failed",
008793
+                             proxy_function,
008793
+                             backend_addr,
008793
+                             worker->s->hostname);
008793
+                backend_addr = backend_addr->next;
008793
+                continue;
008793
+            }
008793
         }
008793
 
008793
         /* Set a timeout on the socket */
008793
@@ -2486,7 +2788,7 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
008793
 
008793
         conn->sock = newsock;
008793
 
008793
-        if (conn->forward) {
008793
+        if (!conn->uds_path && conn->forward) {
008793
             forward_info *forward = (forward_info *)conn->forward;
008793
             /*
008793
              * For HTTP CONNECT we need to prepend CONNECT request before
008793
@@ -2767,7 +3069,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_sync_balancer(proxy_balancer *b, server_rec
008793
                 found = 1;
008793
                 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02402)
008793
                              "re-grabbing shm[%d] (0x%pp) for worker: %s", i, (void *)shm,
008793
-                             worker->s->name);
008793
+                             ap_proxy_worker_name(conf->pool, worker));
008793
                 break;
008793
             }
008793
         }
008793
@@ -3201,6 +3503,39 @@ PROXY_DECLARE(int) ap_proxy_pass_brigade(apr_bucket_alloc_t *bucket_alloc,
008793
     return OK;
008793
 }
008793
 
008793
+/* Fill in unknown schemes from apr_uri_port_of_scheme() */
008793
+
008793
+typedef struct proxy_schemes_t {
008793
+    const char *name;
008793
+    apr_port_t default_port;
008793
+} proxy_schemes_t ;
008793
+
008793
+static proxy_schemes_t pschemes[] =
008793
+{
008793
+    {"fcgi",     8000},
008793
+    {"ajp",      AJP13_DEF_PORT},
008793
+    {"scgi",     4000},
008793
+    { NULL, 0xFFFF }     /* unknown port */
008793
+};
008793
+
008793
+PROXY_DECLARE(apr_port_t) ap_proxy_port_of_scheme(const char *scheme)
008793
+{
008793
+    if (scheme) {
008793
+        apr_port_t port;
008793
+        if ((port = apr_uri_port_of_scheme(scheme)) != 0) {
008793
+            return port;
008793
+        } else {
008793
+            proxy_schemes_t *pscheme;
008793
+            for (pscheme = pschemes; pscheme->name != NULL; ++pscheme) {
008793
+                if (strcasecmp(scheme, pscheme->name) == 0) {
008793
+                    return pscheme->default_port;
008793
+                }
008793
+            }
008793
+        }
008793
+    }
008793
+    return 0;
008793
+}
008793
+
008793
 void proxy_util_register_hooks(apr_pool_t *p)
008793
 {
008793
     APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker);