Welcome! Log In Create A New Profile

Advanced

Re: Parsing Variables to access them in a custom module

Prudhvi Krishna Surapaneni
June 13, 2012 05:34PM
On Thu, Jun 07, 2012 at 02:36:54PM +0400, Maxim Dounin wrote:
> Hello!
>
> On Thu, Jun 07, 2012 at 09:02:44AM +0400, Vladimir Shebordaev wrote:
>
> > 2012/6/7 Prudhvi Krishna Surapaneni <me@prudhvi.net>:
> > > Hi All,
> > > ? ? ? ?I am trying to write a module that needs to consume the regex matched
> > > ? ? ? ?variables like $1 and $2 and pass them as values to the module.
> > >
> > > ? ? ? ?Here is what i am trying to do
> > >
> > > ? ? ? ?/* -- CONFIG -- */
> > >
> > > ? ? ? ? ? ? ? ? ? ? ? ?location ~ /foo/([a-zA-Z0-9]+)/bar/([0-9]+) {
> > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?my_module;
> > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?my_module_first $1;
> > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?my_module_second $2;
> > > ? ? ? ? ? ? ? ? ? ? ? ?}
> > >
> > > ? ? ? ?/* -- CONFIG -- */
> > >
> > > ? ? ? ?Inside my module i have defined them as follows.
> > >
> > > ? ? ? ?/* -- CODE -- */
> > >
> > > ? ? ? ? ? ? ? ?typedef stuct {
> > > ? ? ? ? ? ? ? ? ? ? ? ?ngx_str_t my_module_first;
> > > ? ? ? ? ? ? ? ? ? ? ? ?ngx_str_t my_module_second;
> > > ? ? ? ? ? ? ? ?} ngx_http_my_module_loc_conf_t
> > >
> > > ? ?/* -- CODE -- */
> > >
> > > ? ? ? ?When trying to access the values from those variables i get the
> > > ? ? ? ?value $1 and $2 instead of the substitution. What am i missing?.
> > >
> > > ? ? ? ?Are these variables only availble for the rewrite module?.
> >
> > Not particularly. But you should use the script engine to get captures
> > evaluated at run-time. See, e.g. proxy module for an example.
>
> I would rather recommend using complex values here, as it's
> simpliest way to use variables.
>
> Basically all it needs is using ngx_http_set_complex_value_slot
> instead of ngx_conf_set_str_slot in configuration directive
> definition, and an additional ngx_http_complex_value() call before
> use.
>
> Complete example can be found in secure link module.
>
> Maxim Dounin
>
Hello Maxim,
This is exactly what i wanted. Thank you very much.

-Prudhvi Krishna Surapaneni

> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Parsing Variables to access them in a custom module

Prudhvi Krishna Surapaneni 1012 June 06, 2012 09:44PM

Re: Parsing Variables to access them in a custom module

Vladimir Shebordaev 422 June 07, 2012 01:08AM

Re: Parsing Variables to access them in a custom module

Maxim Dounin 443 June 07, 2012 06:38AM

Re: Parsing Variables to access them in a custom module

Prudhvi Krishna Surapaneni 551 June 13, 2012 05:34PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 156
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready