On 03/18/2014 02:46 PM, Yann Ylavic wrote:
On Tue, Mar 18, 2014 at 2:38 PM, Yann Ylavic <[email protected]> wrote:
Wouldn't it be possible to define wildcard workers when the URL is
known to be a regexp substitution?
For these workers' URLs, the dollars (plus the following digit) could
be replaced by a wildcard (ie. *) and ap_proxy_get_worker() could then
use ap_strcasecmp_match() against the requested URL.
I meant ap_strcmp_match(), this has to be case sensitive...
I've implemented your idea. Can you check the attached patch please? It
fixes the original PR and also ProxyPassMatch with UDS for me.
If it's OK, I will commit it.
Regards,
Jan Kaluza
Index: modules/proxy/mod_proxy.c
===================================================================
--- modules/proxy/mod_proxy.c (revision 1579155)
+++ modules/proxy/mod_proxy.c (working copy)
@@ -1631,8 +1631,29 @@
new->balancer = balancer;
}
else {
- proxy_worker *worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, de_socketfy(cmd->pool, r));
+ proxy_worker *worker;
int reuse = 0;
+ /* When the scheme or the hostname contains '$', skip.
+ * When the path contains '$N', replace '$N' with wildcard. */
+ if (use_regex) {
+ char *r2 = apr_pstrdup(cmd->temp_pool, r);
+ char *x, *y;
+ y = ap_strstr(r2, "://");
+ if (y != NULL) {
+ for (x = y; *y; ++x, ++y) {
+ if (*y != '$') {
+ *x = *y;
+ }
+ else if (apr_isxdigit(*(y + 1))) {
+ *x = '*';
+ y += 1;
+ }
+ }
+ *x = '\0';
+ }
+ r = r2;
+ }
+ worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, r);
if (!worker) {
const char *err = ap_proxy_define_worker(cmd->pool, &worker, NULL, conf, r, 0);
if (err)
Index: modules/proxy/proxy_util.c
===================================================================
--- modules/proxy/proxy_util.c (revision 1579155)
+++ modules/proxy/proxy_util.c (working copy)
@@ -1568,7 +1568,7 @@
if ( ((worker_name_length = strlen(worker->s->name)) <= url_length)
&& (worker_name_length >= min_match)
&& (worker_name_length > max_match)
- && (strncmp(url_copy, worker->s->name, worker_name_length) == 0) ) {
+ && (ap_strcmp_match(url_copy, worker->s->name) == 0) ) {
max_worker = worker;
max_match = worker_name_length;
}
@@ -1580,7 +1580,7 @@
if ( ((worker_name_length = strlen(worker->s->name)) <= url_length)
&& (worker_name_length >= min_match)
&& (worker_name_length > max_match)
- && (strncmp(url_copy, worker->s->name, worker_name_length) == 0) ) {
+ && (ap_strcmp_match(url_copy, worker->s->name) == 0) ) {
max_worker = worker;
max_match = worker_name_length;
}