You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2007/05/12 16:12:25 UTC

svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Author: jim
Date: Sat May 12 07:12:24 2007
New Revision: 537429

URL: http://svn.apache.org/viewvc?view=rev&rev=537429
Log:
Add regex pattern matching to ProxyPass, allowing,
for example:

   ProxyPass ~ \.gif balancer://imagecluster



Modified:
    httpd/httpd/trunk/modules/proxy/mod_proxy.c
    httpd/httpd/trunk/modules/proxy/mod_proxy.h

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.c?view=diff&rev=537429&r1=537428&r2=537429
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.c Sat May 12 07:12:24 2007
@@ -488,6 +488,8 @@
                                                  &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 @@
             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 @@
     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 @@
     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;
 

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.h?view=diff&rev=537429&r1=537428&r2=537429
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.h (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.h Sat May 12 07:12:24 2007
@@ -109,6 +109,7 @@
 struct proxy_alias {
     const char  *real;
     const char  *fake;
+    ap_regex_t  *regex;
 };
 
 struct dirconn_entry {



Re: svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Posted by rb...@rbowen.com.
> Author: jim
> Date: Sat May 12 07:12:24 2007
> New Revision: 537429
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=537429
> Log:
> Add regex pattern matching to ProxyPass, allowing,
> for example:
>
>    ProxyPass ~ \.gif balancer://imagecluster

It would also be really nice to have ProxyPassMatch, a la RedirectMatch
and AliasMatch and DirectoryMatch, et al. Historically, we seem to have a
problem with the '~' syntax in that it's extremely easy to overlook it in
the documentation, or, in certain fonts, to misread it as '-' or '_'.

--Rich

Re: svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Posted by Jim Jagielski <ji...@jaguNET.com>.
On May 13, 2007, at 3:07 PM, Ruediger Pluem wrote:

>
>
> On 05/12/2007 05:10 PM, Ruediger Pluem wrote:
>>
>> On 05/12/2007 04:12 PM, jim@apache.org wrote:
>>
>>> Author: jim
>>> Date: Sat May 12 07:12:24 2007
>>> New Revision: 537429
>>>
>>> URL: http://svn.apache.org/viewvc?view=rev&rev=537429
>>> Log:
>>> Add regex pattern matching to ProxyPass, allowing,
>>> for example:
>>>
>>>   ProxyPass ~ \.gif balancer://imagecluster
>
>>> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/ 
>>> mod_proxy.h?view=diff&rev=537429&r1=537428&r2=537429
>>> ==================================================================== 
>>> ==========
>>> --- httpd/httpd/trunk/modules/proxy/mod_proxy.h (original)
>>> +++ httpd/httpd/trunk/modules/proxy/mod_proxy.h Sat May 12  
>>> 07:12:24 2007
>>> @@ -109,6 +109,7 @@
>>> struct proxy_alias {
>>>     const char  *real;
>>>     const char  *fake;
>>> +    ap_regex_t  *regex;
>>> };
>>
>>
>> Doesn't this require a minor bump?
>
> What about the minor bump? Is it not needed because there is no  
> typedef
> for struct proxy_alias and thus struct proxy_alias is regarded as  
> private?
>

Yep... at least I don't think we need one since it's not
a publicly "used" struct.


Re: svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Posted by Ruediger Pluem <rp...@apache.org>.

On 05/12/2007 05:10 PM, Ruediger Pluem wrote:
> 
> On 05/12/2007 04:12 PM, jim@apache.org wrote:
> 
>>Author: jim
>>Date: Sat May 12 07:12:24 2007
>>New Revision: 537429
>>
>>URL: http://svn.apache.org/viewvc?view=rev&rev=537429
>>Log:
>>Add regex pattern matching to ProxyPass, allowing,
>>for example:
>>
>>   ProxyPass ~ \.gif balancer://imagecluster

>>URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.h?view=diff&rev=537429&r1=537428&r2=537429
>>==============================================================================
>>--- httpd/httpd/trunk/modules/proxy/mod_proxy.h (original)
>>+++ httpd/httpd/trunk/modules/proxy/mod_proxy.h Sat May 12 07:12:24 2007
>>@@ -109,6 +109,7 @@
>> struct proxy_alias {
>>     const char  *real;
>>     const char  *fake;
>>+    ap_regex_t  *regex;
>> };
> 
> 
> Doesn't this require a minor bump?

What about the minor bump? Is it not needed because there is no typedef
for struct proxy_alias and thus struct proxy_alias is regarded as private?

Regards

RĂ¼diger

Re: svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Posted by Jim Jagielski <ji...@jaguNET.com>.
On May 12, 2007, at 11:10 AM, Ruediger Pluem wrote:

>
> Sorry for being picky here: One space too much.
>
> ...

> Again I am picky here: Too many spaces.
>

No worries. Good catches.


Re: svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Posted by Jim Jagielski <ji...@jaguNET.com>.
On May 12, 2007, at 12:45 PM, Joshua Slive wrote:

>> On 05/12/2007 04:12 PM, jim@apache.org wrote:
>> > Author: jim
>> > Date: Sat May 12 07:12:24 2007
>> > New Revision: 537429
>> >
>> > URL: http://svn.apache.org/viewvc?view=rev&rev=537429
>> > Log:
>> > Add regex pattern matching to ProxyPass, allowing,
>> > for example:
>> >
>> >    ProxyPass ~ \.gif balancer://imagecluster
>
> On the configuration consistency side, the "~" thing is deprecated
> everywhere and the standard way to do this is to have a ProxyPassMatch
> directive (see RedirectMatch, DirectoryMatch, etc).
>

Yep. The ProxyPassMatch stuff is currently being worked
(basically, some function name changes ala add_proxy_regex)
but I was hoping to work the support for <DirectoryMatch ..>
into that patch as well before committing... but most likely
I'll just add in ProxyPassMatch first.


Re: svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Posted by Joshua Slive <jo...@slive.ca>.
> On 05/12/2007 04:12 PM, jim@apache.org wrote:
> > Author: jim
> > Date: Sat May 12 07:12:24 2007
> > New Revision: 537429
> >
> > URL: http://svn.apache.org/viewvc?view=rev&rev=537429
> > Log:
> > Add regex pattern matching to ProxyPass, allowing,
> > for example:
> >
> >    ProxyPass ~ \.gif balancer://imagecluster

On the configuration consistency side, the "~" thing is deprecated
everywhere and the standard way to do this is to have a ProxyPassMatch
directive (see RedirectMatch, DirectoryMatch, etc).

Joshua.

Re: svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Posted by Ruediger Pluem <rp...@apache.org>.

On 05/12/2007 04:12 PM, jim@apache.org wrote:
> Author: jim
> Date: Sat May 12 07:12:24 2007
> New Revision: 537429
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=537429
> Log:
> Add regex pattern matching to ProxyPass, allowing,
> for example:
> 
>    ProxyPass ~ \.gif balancer://imagecluster
> 
> 
> 
> Modified:
>     httpd/httpd/trunk/modules/proxy/mod_proxy.c
>     httpd/httpd/trunk/modules/proxy/mod_proxy.h
> 
> Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.c?view=diff&rev=537429&r1=537428&r2=537429
> ==============================================================================
> --- httpd/httpd/trunk/modules/proxy/mod_proxy.c (original)
> +++ httpd/httpd/trunk/modules/proxy/mod_proxy.c Sat May 12 07:12:24 2007
> @@ -510,19 +512,34 @@
>              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);

Sorry for being picky here: One space too much.

> -           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;
> +        }

Again I am picky here: Too many spaces.

> Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.h
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.h?view=diff&rev=537429&r1=537428&r2=537429
> ==============================================================================
> --- httpd/httpd/trunk/modules/proxy/mod_proxy.h (original)
> +++ httpd/httpd/trunk/modules/proxy/mod_proxy.h Sat May 12 07:12:24 2007
> @@ -109,6 +109,7 @@
>  struct proxy_alias {
>      const char  *real;
>      const char  *fake;
> +    ap_regex_t  *regex;
>  };

Doesn't this require a minor bump?

Regards

RĂ¼diger


Re: svn commit: r537429 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy.h

Posted by rb...@rbowen.com.
> Author: jim
> Date: Sat May 12 07:12:24 2007
> New Revision: 537429
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=537429
> Log:
> Add regex pattern matching to ProxyPass, allowing,
> for example:
>
>    ProxyPass ~ \.gif balancer://imagecluster

It would also be really nice to have ProxyPassMatch, a la RedirectMatch
and AliasMatch and DirectoryMatch, et al. Historically, we seem to have a
problem with the '~' syntax in that it's extremely easy to overlook it in
the documentation, or, in certain fonts, to misread it as '-' or '_'.

--Rich