Blame SOURCES/httpd-2.4.6-uds.patch

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

Edit worker settings for ", r);

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