-
Notifications
You must be signed in to change notification settings - Fork 2k
Pass same request method as original to sub-request made by ngx.location.capture #536
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
Comments
@ram-nadella Hey Ram. Long time no see! Glad you're on OpenResty :) Regarding your question, yes, right now you need a Lua table to do the mapping, as in local map = {
GET = ngx.HTTP_GET,
POST = ngx.HTTP_POST,
...
} There is a pending pull request that enables I'm going to merge that soon. BTW, you may also find some of the https://github.com/bakins/lua-resty-http-simple They may be more efficient and more flexible than the |
@ram-nadella BTW, you may want to join the openresty-en mailing list for general discussions around NGINX and/or OpenResty :) Please see https://openresty.org/#Community Thanks! |
Thanks @agentzh!! I have joined the mailing list and took a look at the two modules you mentioned. Seems like the newer one is based on the other. Looks promising. I do have a question about the cache status response header (from Closing this issue since the patch has already been contributed, hoping it gets merged soon. I have worked around the issue for now. |
Found the answer to the header issue in #68 :) Used |
Here is another example to intercept redirects that would lead away from your backend and thus stay on your own website. With GET/POST mapping, POST requests are passed through to the backend as such and are not replaced by GET calls. Note that the default Nginx docker container does not have Lua installed. Therefore, below is my Dockerfile (with somehow awesome nginx-extras package) and a docker-compose.yml file.
|
Hey Mr. agentzh,
It's Ram, your old co-worker :)
Been playing around with nginx lua more these days. I am trying to do something with the power of nginx lua and mofo Sikora's aka @PiotrSikora :P cache purge module.
I've got it compiled by downloading source and adding cache purge repo to bundle folder and editing the
configure
script. I have a content_by_lua_file setup and in my lua code I am able to make a sub-request and when making the sub-request, I want to pass the same request method as the original request.It appears that the
method
key in the options passed tongx.location.capture
expects one of the constants (eg.ngx.HTTP_GET
) where as bothngx.var.request_method
andngx.req.get_method
both return the request method string (GET
).Is there any way to auto-map the request method without doing a switch statement and compare the strings?
(Also, I am not seeing all the headers I expect in the sub-request. I see them all when I hit the location directly using curl but when I do a sub-request using
local res = ngx.location.capture(...)
and print headers by iterating overres.header
I don't see them all)Edit: ignore the part about the missing headers. That was my bad, I was not passing the args from the original request to the sub-request and the header I was expecting is only returned when those particular args are present. oops.
The text was updated successfully, but these errors were encountered: