]> granicus.if.org Git - apache/commitdiff
Add regex pattern matching to ProxyPass, allowing,
authorJim Jagielski <jim@apache.org>
Sat, 12 May 2007 14:12:24 +0000 (14:12 +0000)
committerJim Jagielski <jim@apache.org>
Sat, 12 May 2007 14:12:24 +0000 (14:12 +0000)
for example:

   ProxyPass ~ \.gif balancer://imagecluster

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@537429 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/mod_proxy.c
modules/proxy/mod_proxy.h

index a8b95f4365924c4d2a4b904b11dc150ff0361649..c7428896a86586738e2715caf9e90f1212a17d90 100644 (file)
@@ -488,6 +488,8 @@ static int proxy_trans(request_rec *r)
                                                  &proxy_module);
     const char *fake;
     const char *real;
+    ap_regmatch_t regm[AP_MAX_REG_MATCH];
+    char *found = NULL;
 
     if (r->proxyreq) {
         /* someone has already set up the proxy, it was possibly ourselves
@@ -510,19 +512,34 @@ static int proxy_trans(request_rec *r)
             fake = ent[i].fake;
             real = ent[i].real;
         }
-        len = alias_match(r->uri, fake);
+        if (ent[i].regex) {
+            if (!ap_regexec(ent[i].regex, r->uri, AP_MAX_REG_MATCH, regm, 0)) {
+                if ((real[0] == '!') && (real[1] == '\0')) {
+                    return DECLINED;
+                }
+                found = apr_pstrcat(r->pool, "proxy:", real,
+                                    r->uri, NULL);
+            }
+        }
+        else {
+            len = alias_match(r->uri, fake);
 
-       if (len > 0) {
-           if ((real[0] == '!') && (real[1] == 0)) {
-               return DECLINED;
-           }
+            if (len != 0) {
+                if ((real[0] == '!') && (real[1] == '\0')) {
+                    return DECLINED;
+                }
 
-           r->filename = apr_pstrcat(r->pool, "proxy:", real,
+                found = apr_pstrcat(r->pool, "proxy:", real,
                                      r->uri + len, NULL);
-           r->handler = "proxy-server";
-           r->proxyreq = PROXYREQ_REVERSE;
-           return OK;
-       }
+
+            }
+        }
+        if (found) {
+                r->filename = found;
+                r->handler = "proxy-server";
+                r->proxyreq = PROXYREQ_REVERSE;
+                return OK;
+        }
     }
     return DECLINED;
 }
@@ -1125,11 +1142,17 @@ static const char *
     const apr_array_header_t *arr;
     const apr_table_entry_t *elts;
     int i;
+    int use_regex = 0;
 
     while (*arg) {
         word = ap_getword_conf(cmd->pool, &arg);
-        if (!f)
+        if (!f) {
+            if (!strcmp(word, "~")) {
+                use_regex = 1;
+                continue;
+            }
             f = word;
+        }
         else if (!r)
             r = word;
         else {
@@ -1162,6 +1185,15 @@ static const char *
     new = apr_array_push(conf->aliases);
     new->fake = apr_pstrdup(cmd->pool, f);
     new->real = apr_pstrdup(cmd->pool, r);
+    if (use_regex) {
+        new->regex = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
+        if (new->regex == NULL)
+            return "Regular expression could not be compiled.";
+    }
+    else {
+        new->regex = NULL;
+    }
+
     if (r[0] == '!' && r[1] == '\0')
         return NULL;
 
index c345120553e21ef50fb642d617f6323235992ca3..a8e8a260aef41879241f69a04e5b644fff3e654f 100644 (file)
@@ -109,6 +109,7 @@ struct proxy_remote {
 struct proxy_alias {
     const char  *real;
     const char  *fake;
+    ap_regex_t  *regex;
 };
 
 struct dirconn_entry {