You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2015/12/24 14:00:31 UTC
[Bug 58765] Default behavior change in tomcat 8.0.29-30 context root
redirect process
https://bz.apache.org/bugzilla/show_bug.cgi?id=58765
--- Comment #1 from Konstantin Kolinko <kn...@gmail.com> ---
1. Behaviour can change between minor versions. Actually you are asking for
such a change.
The old behaviour was not removed. You can opt-in for the old behaviour by
setting mapperContextRootRedirectEnabled="true" either on your own web
application or globally in conf/context.xml file.
2. Relying on mapperContextRootRedirectEnabled="true" is bad.
1) It is a Tomcat-specific feature.
2) It is application responsibility to process requests. Relying on Tomcat here
is wrong. E.g. it is incompatible with RemoteIpValve.
http://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Remote_IP_Valve
You filter calls sendRedirect(). You have to change that call to correctly
process requests to the root of web application (getServletPath() is "" and
getPathInfo() is null) by appending '/' to the request URI.
The code to test for this condition looks like the following:
if (request.getServletPath().length() == 0 && request.getPathInfo() == null)
The code to append '/' to requestURI looks like the following:
StringBuilder location = new StringBuilder(requestURI);
location.append('/');
if (request.getQueryString() != null) {
location.append('?');
location.append(request.getQueryString());
}
response.sendRedirect(response.encodeRedirectURL(location.toString()));
Note, that handling such URIs by yourself will improve the network latency of
your application.
Old behaviour:
step 1: request to /test, responds with redirect to /test/
step 2: request to /test/, your filter responds with redirect to
/test/?value=random
step 3: request to /test/?value=random
Now you can send the correct redirect on step 1, skipping step 2 and omitting
one 302 response round trip.
BTW, the following filter mapping in your WEB-INF/web.xml is wrong:
<url-pattern>*</url-pattern>
I guess you meant '/*' here.
The '*' pattern does not end with '/*'. Thus it has to be used as exact match,
not as a prefix match. See chapter 12.2 Specification of Mappings of the
Servlet 3.1 specification.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org