Cache lookup path in ResourceUrlEncodingFilter

Commit https://github.com/spring-projects/spring-framework/commit/2b97d6
introduced a change where the path within the DispatcherServlet is
determined with each call to ResourceUrlProvider.getForRequestUrl.

To avoid repeating that every time a URL is encoded through the
response, we now cache the result of the lookupPath determination in
ResourceUrlEncodingFilter.

Issue: SPR-12332
This commit is contained in:
Rossen Stoyanchev
2014-10-16 21:54:34 -04:00
parent f353a28ff4
commit 3d96c883d1
2 changed files with 26 additions and 3 deletions

View File

@@ -79,7 +79,7 @@ public class ResourceUrlProviderJavaConfigTests {
}
@Test
public void resolvePathWithServletMappingByPrefix() throws Exception {
public void resolvePathWithServletMappedByPrefix() throws Exception {
this.request.setRequestURI("/myapp/myservlet/index");
this.request.setServletPath("/myservlet");
this.filterChain.doFilter(this.request, this.response);
@@ -88,6 +88,16 @@ public class ResourceUrlProviderJavaConfigTests {
resolvePublicResourceUrlPath("/myapp/myservlet/resources/foo.css"));
}
@Test
public void resolvePathNoMatch() throws Exception {
this.request.setRequestURI("/myapp/myservlet/index");
this.request.setServletPath("/myservlet");
this.filterChain.doFilter(this.request, this.response);
assertEquals("/myapp/myservlet/index", resolvePublicResourceUrlPath("/myapp/myservlet/index"));
}
private String resolvePublicResourceUrlPath(String path) {
return this.servlet.wrappedResponse.encodeURL(path);
}