Comments (9)
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.
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.
I've also implemented the ngx.req.get_post_args() method :)
from lua-nginx-module.
consider it resolved :)
from lua-nginx-module.
I can't find ngx.req.get_query_args()
in the current documentation at: http://wiki.nginx.org/HttpLuaModule
from lua-nginx-module.
@thefosk It was later renamed to ngx.req.get_uri_args
.
from lua-nginx-module.
Ok, thanks.
from lua-nginx-module.
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.
@dessite Yes, it is expected.
from lua-nginx-module.
Related Issues (20)
- [feature request] ngx.req.get_body_data() return first n bytes
- why not support lua phase in pre_content phase HOT 1
- [bug]attempt to index global 'sw_tracer ' (a nil value) HOT 3
- Is the nginx 1.24.0 supported? HOT 2
- feature: string buffer support in sock:send()
- ngx_http_lua_module with support of pcre2 HOT 13
- Why can't I use ngx.redirect or ngx.say in the header_filter_by_lua phase HOT 1
- [Introducing a testing framework similar to test::nginx] burl: A simple but flexible HTTP/3 testing framework based on bash and curl
- Why is global environment of each lua handler not isolated when OpenResty's LuaJIT is used?
- Lua code in header_filter phase still runs after ngx.exit(401) is executed in access phase HOT 3
- Shared dictionary cannot retrieve stale data HOT 1
- Content-Length header ignored for HEAD methods HOT 1
- In order to set the headers of the upstream request, I use `ngx.req.set_header` in `rewrite_by_lua_block`, but my upstream endpoint cannot receive such header. HOT 5
- How to share ctx in dfferent locations HOT 2
- http2 request failed HOT 3
- Is the dynamic module available precompiled? HOT 1
- Problem with post request reading in balancer_by_lua_block HOT 2
- huge size response via ngx.location.capture has been truncated HOT 1
- Search in POST request HOT 2
- issue use lua code beside modsecurity module HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-nginx-module.