Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

fairyqb
Copy link
Contributor

@fairyqb fairyqb commented Sep 2, 2020

Summary

PDK:
kong.response.redirect("http://github.com/kong/kong")

Easy use and understanding.

-- @return Nothing; throws an error on invalid input.
-- @usage
-- kong.response.redirect("https://github.com/kong/kong")
function _RESPONSE.redirect(uri)
Copy link
Member

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.

Copy link
Member

@bungle bungle left a 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)
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easy use and understanding.

Copy link
Member

@bungle bungle Oct 23, 2020

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>" })

@kikito
Copy link
Member

kikito commented Nov 27, 2020

@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:

return kong.response.exit(302, "", { Location: "<uri>" })

or:

return kong.response.exit(302, nil, { Location: "<uri>" })

Your proposal ultimately amounts to a slightly simpler set of params, and checking that the uri param is valid. However it has maintenance cost in the form of tests and documentation. I feel that the benefit does not justify the cost in this particular case. In order to avoid other misunderstanding like this, I suggest opening an issue and asking whether it is needed first.

Please don't let this prevent you from sending other PRs in the future! Again, we deeply appreciate it.

@kikito kikito closed this Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants