Summary: | Default behavior change in tomcat 8.0.29-30 context root redirect process | ||
---|---|---|---|
Product: | Tomcat 8 | Reporter: | Amb <jrivard> |
Component: | Catalina | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | 8.0.30 | ||
Target Milestone: | ---- | ||
Hardware: | PC | ||
OS: | Linux |
Description
Amb
2015-12-24 05:42:18 UTC
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. Fixed in 8.0.x (for 8.0.31 onwards) and 7.0.x (for 7.0.68 onwards). The default was also changed in trunk and 6.0.x but no release had been made with the previous default so this bug did not affect any release of those branches. |