-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing querystring vars #15
Comments
On Thu, Jan 27, 2011 at 6:30 PM, GitHub noreply@github.com wrote:
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
Because nginx's builtin variables $arg_FOO already provide this functionality, we do not provide any special interface in ngx_lua.
Yeah, it makes sense to provide native interface to access those parameters just like PHP. We'll work on that.
Yeah, for now you need to parse the query string in ngx.var.query_string yourself then...sorry about that.
Indeed :)
Agreed :) Thanks! |
…lves github issue #15. thanks Bertrand Mansion (golgote).
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! |
I've also implemented the ngx.req.get_post_args() method :) |
consider it resolved :) |
I can't find |
@thefosk It was later renamed to |
Ok, thanks. |
Not sure if it is an issue or works as designed but I found that if you refer to query string by
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
it is case sensitive so "name=nginx" is not the same as "Name=nginx" in your request |
@dessite Yes, it is expected. |
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. Is this the way nginx stores them internally ? 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...).
Then, I was wondering if there was a way to deal with request vars with the same name, for example : ?num=1&num=2
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.
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.
The text was updated successfully, but these errors were encountered: