Shared read-only instance of UrlPathHelper
In many places UrlPathHelper is created and used without any customizations, in some cases repeatedly. This commit adds a shared read-only UrlPathHelper instance with default settings. See gh-25100
This commit is contained in:
@@ -132,8 +132,7 @@ class DefaultServerRequest implements ServerRequest {
|
||||
public String path() {
|
||||
String path = (String) servletRequest().getAttribute(HandlerMapping.LOOKUP_PATH);
|
||||
if (path == null) {
|
||||
UrlPathHelper helper = new UrlPathHelper();
|
||||
path = helper.getLookupPathForRequest(servletRequest());
|
||||
path = UrlPathHelper.defaultInstance.getLookupPathForRequest(servletRequest());
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
boolean useTrailingSlashMatch, @Nullable List<String> fileExtensions) {
|
||||
|
||||
this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns));
|
||||
this.pathHelper = urlPathHelper != null ? urlPathHelper : new UrlPathHelper();
|
||||
this.pathHelper = urlPathHelper != null ? urlPathHelper : UrlPathHelper.defaultInstance;
|
||||
this.pathMatcher = pathMatcher != null ? pathMatcher : new AntPathMatcher();
|
||||
this.useSuffixPatternMatch = useSuffixPatternMatch;
|
||||
this.useTrailingSlashMatch = useTrailingSlashMatch;
|
||||
|
||||
@@ -91,7 +91,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
|
||||
new ParameterizedTypeReference<List<ResourceRegion>>() { }.getType();
|
||||
|
||||
|
||||
private static final UrlPathHelper decodingUrlPathHelper = new UrlPathHelper();
|
||||
private static final UrlPathHelper decodingUrlPathHelper = UrlPathHelper.defaultInstance;
|
||||
|
||||
private static final UrlPathHelper rawUrlPathHelper = new UrlPathHelper();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -37,7 +37,7 @@ import org.springframework.web.util.WebUtils;
|
||||
*/
|
||||
public class ServletCookieValueMethodArgumentResolver extends AbstractCookieValueMethodArgumentResolver {
|
||||
|
||||
private UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||
private UrlPathHelper urlPathHelper = UrlPathHelper.defaultInstance;
|
||||
|
||||
|
||||
public ServletCookieValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory) {
|
||||
|
||||
@@ -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.
|
||||
@@ -54,7 +54,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||
private UrlPathHelper urlPathHelper = UrlPathHelper.defaultInstance;
|
||||
|
||||
private PathMatcher pathMatcher = new AntPathMatcher();
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
|
||||
private int flashMapTimeout = 180;
|
||||
|
||||
private UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||
private UrlPathHelper urlPathHelper = UrlPathHelper.defaultInstance;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,7 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromServletMapping(HttpServletRequest request) {
|
||||
ServletUriComponentsBuilder builder = fromContextPath(request);
|
||||
if (StringUtils.hasText(new UrlPathHelper().getPathWithinServletMapping(request))) {
|
||||
if (StringUtils.hasText(UrlPathHelper.defaultInstance.getPathWithinServletMapping(request))) {
|
||||
builder.path(request.getServletPath());
|
||||
}
|
||||
return builder;
|
||||
|
||||
Reference in New Issue
Block a user