-
Notifications
You must be signed in to change notification settings - Fork 98
HttpServletResponse#sendRedirect(String) could use some improvement; needs 301/302/303 support; needs way to set request body #74
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
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
|
Hi @markt-asf For sendRedirect(String, int) or sendRedirect(String, int, boolean), should the API or doc specify what to do if the user use arbitrary status code other than 301, 302, or 303? Should the default 302 be used for that case? |
The use of
The existence of a There's no reason to limit the status codes to just 301, 302, or 303. |
+1 |
Currently, HttpServletResponse#sendRedirect(String) specifies the following hard-wired behavior that cannot be changed:
I have three issues with this behavior that I summarize below, and at the bottom I propose a solution:
Issue 1
RFC 2616, says the following about 302 Found:
The two keys here are 1) that the spec says browsers MUST NOT automatically redirect the request and 2) that there could be some browsers that send the second request with the original method (POST, PUT, etc.).
As an application not concerned with legacy HTTP/1.0 user-agents and more concerned with ensuring that user agents do not prompt the user for permission to redirect and do not redirect using a POST or a PUT, etc., I prefer to use the 303 See Other response as opposed to the 302 Found response:
Issue 2
As an application that has recently been refactored, I want to be able to easily send a permanent redirect to users for old URLs that have been removed and should be changed. This can be achieved with the 301 Moved Permanently response:
Issue 3
The exact wording of the short hypertext response included with the current 302 Found responses is not consistent across containers. As an application developer that cares about branding and consistency, I would like to be able to customize this text within my code and do so in a way that is consistent across all containers.
Recommendation
I believe the following additions to the Servlet API will greatly improve the current HttpServletResponse#sendRedirect(String) and satisfy the needs outlined here.
The text was updated successfully, but these errors were encountered: