Welcome! Log In Create A New Profile

Advanced

How to replace http request parameter value

Posted by TwilightFeel 
How to replace http request parameter value
November 24, 2011 11:34AM
Hi! I'm using nginx to proxy requests from clients to JSON data provider backend. How i can replace one of the request parameters, if one exists, but doesn't satisfies regexp ^\d{1,2}$?

Now i'm at this point:

location / {
if ( $arg_limit !~ "^\d{1,2}$" ) {
rewrite ^(.*)$ $1?limit=10 break;
}

proxy_pass http://data_provider;
}

It works, when limit argument aren't defined, but take place for double limit arguments, if one defined in the request.

Required behaviour:

# no limit arg, add one with default value
/path?key=1 → /path?limit=10&key=1

# arg value satisfies regexp, don't rewrite
/path?key=1&limit=50 → /path?key=1&limit=50

# arg value doesn't satisfies regexp, replace with default
/path?key=1&limit=5000 → /path?limit=10&key=1

Arguments order doesn't matter, of course.

nginx/1.0.10
configure arguments:
--with-ipv6 --with-pcre --with-http_ssl_module
--with-http_addition_module --with-http_xslt_module
--with-http_geoip_module --with-http_gzip_static_module
--with-http_secure_link_module
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 273
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