Shared read-only instances of UrlPathHelper

UrlPathHelper is often created and used without customizations or with
the same customizations. This commit introduces re-usable, instances.
Effectively a backport of commit 23233c.

Closes gh-25690
This commit is contained in:
Rossen Stoyanchev
2020-09-03 20:21:00 +01:00
parent caa22b7291
commit bdcb189e50
10 changed files with 77 additions and 42 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,8 +83,6 @@ public class MockHttpServletRequestBuilder
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
private final String method;
@@ -697,7 +695,7 @@ public class MockHttpServletRequestBuilder
}
String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
this.pathInfo = (StringUtils.hasText(extraPath) ?
urlPathHelper.decodeRequestString(request, extraPath) : null);
UrlPathHelper.defaultInstance.decodeRequestString(request, extraPath) : null);
}
request.setPathInfo(this.pathInfo);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,8 +44,6 @@ final class PatternMappingFilterProxy implements Filter {
private static final String PATH_MAPPING_PATTERN = "/*";
private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
private final Filter delegate;
/** Patterns that require an exact match, e.g. "/test" */
@@ -95,7 +93,7 @@ final class PatternMappingFilterProxy implements Filter {
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestPath = urlPathHelper.getPathWithinApplication(httpRequest);
String requestPath = UrlPathHelper.defaultInstance.getPathWithinApplication(httpRequest);
if (matches(requestPath)) {
this.delegate.doFilter(request, response, filterChain);