summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Jagielski <jim@apache.org>2013-10-11 18:12:41 +0200
committerJim Jagielski <jim@apache.org>2013-10-11 18:12:41 +0200
commite40e0a785b3b9ab29355bb035928b36b4806f1dc (patch)
tree05126edfe726292f15e155710e25c857cbf061fb
parentsave a possible lookup (diff)
downloadapache2-e40e0a785b3b9ab29355bb035928b36b4806f1dc.tar.xz
apache2-e40e0a785b3b9ab29355bb035928b36b4806f1dc.zip
Reformat the UDS support inline with a new naming structure.
Use a flag for speed for testing. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1531340 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--docs/manual/mod/mod_proxy.xml4
-rw-r--r--modules/proxy/mod_proxy.c4
-rw-r--r--modules/proxy/mod_proxy.h1
-rw-r--r--modules/proxy/mod_proxy_balancer.c2
-rw-r--r--modules/proxy/proxy_util.c87
5 files changed, 57 insertions, 41 deletions
diff --git a/docs/manual/mod/mod_proxy.xml b/docs/manual/mod/mod_proxy.xml
index feb927ce8f..30fd2a7845 100644
--- a/docs/manual/mod/mod_proxy.xml
+++ b/docs/manual/mod/mod_proxy.xml
@@ -823,9 +823,9 @@ expressions</description>
<directive>ProxyPass</directive>.</note>
<p>Support for using a Unix Domain Socket is available by using a target
- of <code>uds=percent-encoded-path</code>. For example, to target the
+ of <code>|sock:/path/lis.sock</code>. For example, to target the
UDS at /home/www/socket you would use
- <code>http://uds=%2Fhome%2Fwww%2Fsocket</code></p>
+ <code>http://localhost/|sock:/home/www.socket</code></p>
<p>Suppose the local server has address <code>http://example.com/</code>;
then</p>
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
index 96f32304c0..85966ad231 100644
--- a/modules/proxy/mod_proxy.c
+++ b/modules/proxy/mod_proxy.c
@@ -2017,8 +2017,8 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
if ((err = ap_proxy_define_worker(cmd->pool, &worker, balancer, conf, name, 0)) != NULL)
return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01148)
- "Defined worker '%s' for balancer '%s'",
- worker->s->name, balancer->s->name);
+ "Defined worker '%s%s' for balancer '%s'",
+ worker->s->name, (worker->s->uds ? "|" : ""), balancer->s->name);
PROXY_COPY_CONF_PARAMS(worker, conf);
} else {
reuse = 1;
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
index 8dce385dcb..2d0af8afaf 100644
--- a/modules/proxy/mod_proxy.h
+++ b/modules/proxy/mod_proxy.h
@@ -388,6 +388,7 @@ typedef struct {
unsigned int keepalive_set:1;
unsigned int disablereuse_set:1;
unsigned int was_malloced:1;
+ unsigned int uds:1;
} proxy_worker_shared;
#define ALIGNED_PROXY_WORKER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_worker_shared)))
diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c
index 5fd9e1513c..a32f8b8dd8 100644
--- a/modules/proxy/mod_proxy_balancer.c
+++ b/modules/proxy/mod_proxy_balancer.c
@@ -1531,7 +1531,7 @@ static int balancer_handler(request_rec *r)
ap_escape_uri(r->pool, worker->s->name),
"&nonce=", balancer->s->nonce,
"\">", NULL);
- ap_rvputs(r, worker->s->name, "</a></td>", NULL);
+ ap_rvputs(r, worker->s->name, (worker->s->uds ? "|" : ""), "</a></td>", NULL);
ap_rvputs(r, "<td>", ap_escape_html(r->pool, worker->s->route),
NULL);
ap_rvputs(r, "</td><td>",
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
index 1d989a3a64..ddf7e09182 100644
--- a/modules/proxy/proxy_util.c
+++ b/modules/proxy/proxy_util.c
@@ -40,7 +40,6 @@
APLOG_USE_MODULE(proxy);
-#define UDS_SOCKET_STRING "uds="
/*
* Opaque structure containing target server info when
* using a forward proxy.
@@ -1566,6 +1565,7 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
return max_worker;
}
+
/*
* To create a worker from scratch first we define the
* specifics of the worker; this is all local data.
@@ -1581,10 +1581,25 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
int do_malloc)
{
int rv;
- apr_uri_t uri;
+ apr_uri_t uri, urisock;
proxy_worker_shared *wshared;
- char *ptr;
+ char *ptr, *sockpath = NULL;
+ /* Look to see if we are using UDS:
+ require format: http://localhost/whatever|sock:/path
+ This results in talking http to the socket at /whatever/path
+ */
+ ptr = ap_strchr((char *)url, '|');
+ if (ptr) {
+ *ptr = '\0';
+ rv = apr_uri_parse(p, ptr+1, &urisock);
+ if (rv == APR_SUCCESS && !strcasecmp(urisock.scheme, "sock")) {
+ sockpath = urisock.path;
+ }
+ else {
+ *ptr = '|';
+ }
+ }
rv = apr_uri_parse(p, url, &uri);
if (rv != APR_SUCCESS) {
@@ -1596,6 +1611,11 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
ap_str_tolower(uri.hostname);
ap_str_tolower(uri.scheme);
+ if (sockpath) {
+ uri.hostname = "localhost";
+ uri.path = apr_pstrcat(p, uri.path, (*sockpath == '/' ? "" : "/"),
+ sockpath, NULL);
+ }
/*
* Workers can be associated w/ balancers or on their
* own; ie: the generic reverse-proxy or a worker
@@ -1650,6 +1670,7 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
wshared->hash.def = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_DEFAULT);
wshared->hash.fnv = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_FNV);
wshared->was_malloced = (do_malloc != 0);
+ wshared->uds = (sockpath != NULL);
(*worker)->hash = wshared->hash;
(*worker)->context = NULL;
@@ -2030,7 +2051,30 @@ PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
(*conn)->worker = worker;
(*conn)->close = 0;
(*conn)->inreslist = 0;
- (*conn)->uds_path = NULL;
+
+ if (worker->s->uds) {
+ if ((*conn)->uds_path == NULL) {
+ apr_uri_t puri;
+ if (apr_uri_parse(worker->cp->pool, worker->s->name, &puri) == APR_SUCCESS) {
+ (*conn)->uds_path = apr_pstrdup(worker->cp->pool, puri.path);
+ }
+ }
+ if ((*conn)->uds_path) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO()
+ "%s: has determined UDS as %s",
+ proxy_function, (*conn)->uds_path);
+ }
+ else {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO()
+ "%s: cannot parse for UDS (%s)",
+ proxy_function, worker->s->name);
+
+ }
+ }
+ else {
+ (*conn)->uds_path = NULL;
+ }
+
return OK;
}
@@ -2047,30 +2091,6 @@ PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
return OK;
}
-/*
- * Decodes a '%' escaped string, and returns the number of characters
- */
-static int decodeenc(char *x)
-{
- int i, j, ch;
-
- if (x[0] == '\0') {
- /* special case for no characters */
- return 0;
- }
- for (i = 0, j = 0; x[i] != '\0'; i++, j++) {
- /* decode it if not already done */
- ch = x[i];
- if (ch == '%' && apr_isxdigit(x[i + 1]) && apr_isxdigit(x[i + 2])) {
- ch = ap_proxy_hex2c(&x[i + 1]);
- i += 2;
- }
- x[j] = ch;
- }
- x[j] = '\0';
- return j;
-}
-
PROXY_DECLARE(int)
ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
proxy_server_conf *conf,
@@ -2127,7 +2147,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
* spilling the cached addr from the worker.
*/
if (!conn->hostname || !worker->s->is_address_reusable ||
- worker->s->disablereuse || strncmp(conn->hostname, UDS_SOCKET_STRING, sizeof(UDS_SOCKET_STRING)-1) == 0) {
+ worker->s->disablereuse || worker->s->uds) {
if (proxyname) {
conn->hostname = apr_pstrdup(conn->pool, proxyname);
conn->port = proxyport;
@@ -2165,12 +2185,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
conn->port = uri->port;
}
socket_cleanup(conn);
- if (strncmp(conn->hostname, UDS_SOCKET_STRING, sizeof(UDS_SOCKET_STRING)-1) == 0) {
- char *uds_path = apr_pstrdup(conn->pool, conn->hostname + sizeof(UDS_SOCKET_STRING) - 1);
- decodeenc(uds_path);
- conn->uds_path = uds_path;
- }
- else if (!worker->s->is_address_reusable || worker->s->disablereuse) {
+ if (!worker->s->uds && worker->s->is_address_reusable && !worker->s->disablereuse) {
/*
* Only do a lookup if we should not reuse the backend address.
* Otherwise we will look it up once for the worker.
@@ -2181,7 +2196,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
conn->pool);
}
}
- if (worker->s->is_address_reusable && !worker->s->disablereuse) {
+ if (!worker->s->uds && worker->s->is_address_reusable && !worker->s->disablereuse) {
/*
* Looking up the backend address for the worker only makes sense if
* we can reuse the address.