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

Edit worker settings for ", r);

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