njs: get raw requestURI or full querystring
    Sergey A. Osokin 
    osa at freebsd.org.ru
       
    Wed Apr 28 02:50:38 UTC 2021
    
    
  
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
    
    
More information about the nginx-devel
mailing list