Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

query param support? #10

Open
viliman opened this issue Sep 8, 2015 · 4 comments
Open

query param support? #10

viliman opened this issue Sep 8, 2015 · 4 comments

Comments

@viliman
Copy link

viliman commented Sep 8, 2015

I've given this a try now and like it much. However, it is unclear to me how this works with query parameters? There was example with POST but I would like to use with GET and query params such as /hello?name=Peter is this possible?

@viliman
Copy link
Author

viliman commented Sep 11, 2015

The problem was that the query params mixed the matching in router.lua

So I removed them from the URI that was feeding the router.. with following workaround code:
local uri = ngx.var.request_uri
local uri_without_query_params
local from, to, err = ngx.re.find(uri, "([^?.]+)")
if from then
ngx.say("from: ", from)
ngx.say("to: ", to)
uri_without_query_params = string.sub(uri, from, to)
ngx.say("matched: ", uri_without_query_params)
else
if err then
ngx.say("error: ", err)
return
end
ngx.say("not matched!")
end

-- Echo the ngix requests to router module
if r:execute(
ngx.var.request_method,
uri_without_query_params,
ngx.req.get_uri_args()
) then
ngx.status = 200
else
ngx.status = 404
ngx.print("Not found!")
end

@rohitjoshi
Copy link

I had the same issue and submitted below PR which will fix this issue.
#14

@rohitjoshi
Copy link

alternate option is to use ngx.var.uri instead of ngx.var.request_uri or your local variable uri_without_query_params

@viliman
Copy link
Author

viliman commented Nov 19, 2015

Thanks for info and the fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants