-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat/pdk.kong.response.redirect #6297
Conversation
-- @return Nothing; throws an error on invalid input. | ||
-- @usage | ||
-- kong.response.redirect("https://github.com/kong/kong") | ||
function _RESPONSE.redirect(uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest that to add an optional status parameter here as _RESPONSE.redirect(uri, status?)
, keep the consistency with https://github.com/openresty/lua-nginx-module#ngxredirect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments
end | ||
|
||
ngx.header[LOCATION_HEADER_NAME] = uri | ||
return ngx.exit(301) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
302
is in general a better default, but it should also be an argument.
We also need to construct body. Here is what Nginx does: http://lxr.nginx.org/source/src/http/ngx_http_special_response.c
We can add Kong twist to it.
This should also use kong.response.exit
to make short-circuiting work correctly. I am also not sure about the validation there. Is it needed, is it correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy use and understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note here, with our current PDK, you can do this (it implements proper short-circuiting logic too):
return kong.response.exit(302, "", { Location: "<uri>" })
OR (if you prefer Nginx default content for 302):
return kong.response.exit(302, nil, { Location: "<uri>" })
@fairyqb we are very grateful for the time and effort you put into this PR, but I have decided not to include it. As @bungle has mentioned, redirects can be currently implemented with:
or:
Your proposal ultimately amounts to a slightly simpler set of params, and checking that the Please don't let this prevent you from sending other PRs in the future! Again, we deeply appreciate it. |
Summary
PDK:
kong.response.redirect("http://github.com/kong/kong")
Easy use and understanding.