njs: get raw requestURI or full querystring

Gunter Grodotzki gunter at grodotzki.com
Wed Apr 28 05:45:37 UTC 2021


Unfortunately r.args is empty if no key/value pair is given.

> On 28 Apr 2021, at 04:50, Sergey A. Osokin <osa at freebsd.org.ru> wrote:
> 
> Hi Gunter,
> 
> hope you're doing well these days.
> 
>> On Tue, Apr 27, 2021 at 11:21:26PM +0200, Gunter Grodotzki wrote:
>> Hi all,
>> 
>> I would love to try out nginx njs for https://url.rw
>> 
>> Unfortunately I do not seem to be able to get the value of the querystring e.g.
>> in my case it does not contain any key-value pairs:
>> 
>> https://url.rw/?https%3A%2F%2Flifeofguenter.de
>> 
>> I am interested in the value “https%3A%2F%2Flifeofguenter.de” (well ideally
>> urldecoded).
> 
> According to https://nginx.org/en/docs/njs/reference.html#http, the HTTP
> request object has arguments:
> 
> r.args{}
>    request arguments object, read-only
> 
> It's possible to get an argument with the following example:
> 
>    for (var arg in r.args) {
>        if (arg != '') {
>            str += arg;
>            break;
>        }
>    }
> 
> The str can be unescaped then with the following function,
> http://nginx.org/en/docs/njs/reference.html#querystring_unescape
> 
> querystring.unescape(string)
> 
>    Performs decoding of URL percent-encoded characters of the string,
>    returns an unescaped query string.
> 
> 
> Hope that helps.
> 
> -- 
> Sergey Osokin
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel


More information about the nginx-devel mailing list