Giter Site home page Giter Site logo

Comments (9)

agentzh avatar agentzh commented on June 21, 2024

On Thu, Jan 27, 2011 at 6:30 PM, GitHub [email protected] wrote:

golgote reported an issue:

I actually have two questions related to querystring vars, those are just to start a discussion :)

First I was wondering why you prefix the variables with 'arg_' when they are accessed with ngx.var["arg_num"] for example.

If you do read ngx_lua's documentation more carefully, the syntax ngx.var.FOO is how to access nginx variables $FOO from within Lua. So ngx.var.arg_FOO is accessing nginx's special variable $arg_FOO which is documented here:

http://wiki.nginx.org/NginxHttpCoreModule#.24arg_PARAMETER

Is this the way nginx stores them internally ?

Because nginx's builtin variables $arg_FOO already provide this functionality, we do not provide any special interface in ngx_lua.

I thought it could make more sense to just use ngx.var["num"], this way no need to prefix variable names with "arg_". I realize this is a BC break though, so maybe having ngx.vars["num"] or like with PHP, ngx._get["num"] and ngx._post["num"] to make a difference between variables from GET, POST (and COOKIE, ENV actually...).

Yeah, it makes sense to provide native interface to access those parameters just like PHP. We'll work on that.

Then, I was wondering if there was a way to deal with request vars with the same name, for example : ?num=1&num=2

Yeah, for now you need to parse the query string in ngx.var.query_string yourself then...sorry about that.

IIRC, mod_lua from Apache 2.4 converts the variable to a table in this case. PHP on the other side insist on having brakets like this : ?num[]=1&num[]=2 which can be handy because it also works with num[x]=1&num[y]=2 to create an associative array.

Indeed :)

Maybe all of this could be done on the Lua side if I parse ngx.var["request_uri"] or the body. I just thought it could be easier if it was done in the module directly.

Agreed :)

Thanks!
-agentzh

from lua-nginx-module.

agentzh avatar agentzh commented on June 21, 2024

I've already implemented the ngx.req.get_query_args() method in git master. Could you please give it a try? Please take a look at the documentation for details. Thanks!

from lua-nginx-module.

agentzh avatar agentzh commented on June 21, 2024

I've also implemented the ngx.req.get_post_args() method :)

from lua-nginx-module.

agentzh avatar agentzh commented on June 21, 2024

consider it resolved :)

from lua-nginx-module.

subnetmarco avatar subnetmarco commented on June 21, 2024

I can't find ngx.req.get_query_args() in the current documentation at: http://wiki.nginx.org/HttpLuaModule

from lua-nginx-module.

agentzh avatar agentzh commented on June 21, 2024

@thefosk It was later renamed to ngx.req.get_uri_args.

from lua-nginx-module.

subnetmarco avatar subnetmarco commented on June 21, 2024

Ok, thanks.

from lua-nginx-module.

dessite avatar dessite commented on June 21, 2024

Not sure if it is an issue or works as designed but I found that if you refer to query string by

ngx.say(ngx.var.arg_name)

it will get the query string case insensitive, so no difference if you had "name=nginx" or "Name=nginx" or "NaMe=nginx" in your request, but if you do

local query_string = ngx.req.get_uri_args()
ngx.say(query_string["name"])
ngx.say(query_string["Name"])

it is case sensitive so "name=nginx" is not the same as "Name=nginx" in your request

from lua-nginx-module.

agentzh avatar agentzh commented on June 21, 2024

@dessite Yes, it is expected.

from lua-nginx-module.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.