[PATCH] implement a $location variable

David Gwynne david at gwynne.id.au
Tue Oct 16 23:43:21 UTC 2012


On 17/10/2012, at 12:46 AM, Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
> 
> On Tue, Oct 16, 2012 at 11:16:00PM +1000, David Gwynne wrote:
> 
> [...]
> 
>>>> +    if (clcf->regex) {
>>>> +        rc = ngx_regex_exec(clcf->regex->regex, &r->uri, captures, 3);
>>>> +
>>>> +        if (rc == NGX_REGEX_NO_MATCHED) {
>>>> +            return NGX_ERROR;
>>>> +        }
>>>> +
>>>> +        v->data = r->uri.data + captures[0];
>>>> +        v->len = captures[1] - captures[0];
>>> 
>>> Note that result is actually unstable in the regexp location case, 
>>> as the code re-executes regular expression against a possibly 
>>> changed URI.
>> 
>> is there a way to keep the equivalent of $0 around after the original regex is run?
> 
> It can be easily done without any additional code, using named 
> captures:
> 
>    location ~ ^(?<matched>/foo|/bar) {
>        # here one can use $matched
>    }

i can live with that. i would still like a $location variable though. it simplifies the creation of reusable blocks for front end controllers. i can provide an example if you want. should i respin the diff without the regex bits?

dlg


More information about the nginx-devel mailing list