Turn off use of path extensions by default
Closes gh-23915
This commit is contained in:
@@ -49,19 +49,19 @@ import org.springframework.web.accept.ParameterContentNegotiationStrategy;
|
||||
* <th>Enabled Or Not</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #favorPathExtension}</td>
|
||||
* <td>true</td>
|
||||
* <td>{@link org.springframework.web.accept.PathExtensionContentNegotiationStrategy
|
||||
* PathExtensionContentNegotiationStrategy}</td>
|
||||
* <td>Enabled</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #favorParameter}</td>
|
||||
* <td>false</td>
|
||||
* <td>{@link ParameterContentNegotiationStrategy}</td>
|
||||
* <td>Off</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #favorPathExtension}</td>
|
||||
* <td>false (as of 5.3)</td>
|
||||
* <td>{@link org.springframework.web.accept.PathExtensionContentNegotiationStrategy
|
||||
* PathExtensionContentNegotiationStrategy}</td>
|
||||
* <td>Off</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #ignoreAcceptHeader}</td>
|
||||
* <td>false</td>
|
||||
* <td>{@link HeaderContentNegotiationStrategy}</td>
|
||||
@@ -123,18 +123,34 @@ public class ContentNegotiationConfigurer {
|
||||
this.factory.setStrategies(strategies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a request parameter ("format" by default) should be used to
|
||||
* determine the requested media type. For this option to work you must
|
||||
* register {@link #mediaType(String, MediaType) media type mappings}.
|
||||
* <p>By default this is set to {@code false}.
|
||||
* @see #parameterName(String)
|
||||
*/
|
||||
public ContentNegotiationConfigurer favorParameter(boolean favorParameter) {
|
||||
this.factory.setFavorParameter(favorParameter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query parameter name to use when {@link #favorParameter} is on.
|
||||
* <p>The default parameter name is {@code "format"}.
|
||||
*/
|
||||
public ContentNegotiationConfigurer parameterName(String parameterName) {
|
||||
this.factory.setParameterName(parameterName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the path extension in the URL path should be used to determine
|
||||
* the requested media type.
|
||||
* <p>By default this is set to {@code true} in which case a request
|
||||
* for {@code /hotels.pdf} will be interpreted as a request for
|
||||
* {@code "application/pdf"} regardless of the 'Accept' header.
|
||||
* @deprecated as of 5.2.4. See class-level note in
|
||||
* {@link ContentNegotiationManagerFactoryBean} on the deprecation of path
|
||||
* extension config options. As there is no replacement for this method,
|
||||
* for the time being it's necessary to continue using it in order to set it
|
||||
* to {@code false}. In 5.3 when {@code false} becomes the default, use of
|
||||
* this property will no longer be necessary.
|
||||
* <p>By default this is set to {@code false} in which case path extensions
|
||||
* have no impact on content negotiation.
|
||||
* @deprecated as of 5.2.4. See deprecation note on
|
||||
* {@link ContentNegotiationManagerFactoryBean#setFavorPathExtension(boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public ContentNegotiationConfigurer favorPathExtension(boolean favorPathExtension) {
|
||||
@@ -190,9 +206,8 @@ public class ContentNegotiationConfigurer {
|
||||
* to any media type. Setting this to {@code false} will result in an
|
||||
* {@code HttpMediaTypeNotAcceptableException} if there is no match.
|
||||
* <p>By default this is set to {@code true}.
|
||||
* @deprecated as of 5.2.4. See class-level note in
|
||||
* {@link ContentNegotiationManagerFactoryBean} on the deprecation of path
|
||||
* extension config options.
|
||||
* @deprecated as of 5.2.4. See deprecation note on
|
||||
* {@link ContentNegotiationManagerFactoryBean#setIgnoreUnknownPathExtensions(boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public ContentNegotiationConfigurer ignoreUnknownPathExtensions(boolean ignore) {
|
||||
@@ -224,27 +239,6 @@ public class ContentNegotiationConfigurer {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a request parameter ("format" by default) should be used to
|
||||
* determine the requested media type. For this option to work you must
|
||||
* register {@link #mediaType(String, MediaType) media type mappings}.
|
||||
* <p>By default this is set to {@code false}.
|
||||
* @see #parameterName(String)
|
||||
*/
|
||||
public ContentNegotiationConfigurer favorParameter(boolean favorParameter) {
|
||||
this.factory.setFavorParameter(favorParameter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query parameter name to use when {@link #favorParameter} is on.
|
||||
* <p>The default parameter name is {@code "format"}.
|
||||
*/
|
||||
public ContentNegotiationConfigurer parameterName(String parameterName) {
|
||||
this.factory.setParameterName(parameterName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to disable checking the 'Accept' request header.
|
||||
* <p>By default this value is set to {@code false}.
|
||||
|
||||
@@ -69,9 +69,9 @@ public class PathMatchConfigurer {
|
||||
* @see #registeredSuffixPatternMatch
|
||||
* @deprecated as of 5.2.4. See class-level note in
|
||||
* {@link RequestMappingHandlerMapping} on the deprecation of path extension
|
||||
* config options. As there is no replacement for this method, for the time
|
||||
* being it's necessary to set it to {@code false}. In 5.3 when {@code false}
|
||||
* becomes the default, use of this property will no longer be necessary.
|
||||
* config options. As there is no replacement for this method, in 5.2.x it is
|
||||
* necessary to set it to {@code false}. In 5.3 {@code false} becomes the
|
||||
* default, and use of this property is longer be necessary.
|
||||
*/
|
||||
@Deprecated
|
||||
public PathMatchConfigurer setUseSuffixPatternMatch(Boolean suffixPatternMatch) {
|
||||
@@ -150,9 +150,8 @@ public class PathMatchConfigurer {
|
||||
|
||||
/**
|
||||
* Whether to use registered suffixes for pattern matching.
|
||||
* @deprecated as of 5.2.4. See class-level note in
|
||||
* {@link RequestMappingHandlerMapping} on the deprecation of path extension
|
||||
* config options.
|
||||
* @deprecated as of 5.2.4, see deprecation note on
|
||||
* {@link #setUseSuffixPatternMatch(Boolean)}.
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
@@ -162,9 +161,8 @@ public class PathMatchConfigurer {
|
||||
|
||||
/**
|
||||
* Whether to use registered suffixes for pattern matching.
|
||||
* @deprecated as of 5.2.4. See class-level note in
|
||||
* {@link RequestMappingHandlerMapping} on the deprecation of path extension
|
||||
* config options.
|
||||
* @deprecated as of 5.2.4, see deprecation note on
|
||||
* {@link #setUseRegisteredSuffixPatternMatch(Boolean)}.
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
|
||||
@@ -543,7 +543,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||
|
||||
private boolean trailingSlashMatch = true;
|
||||
|
||||
private boolean suffixPatternMatch = true;
|
||||
private boolean suffixPatternMatch = false;
|
||||
|
||||
private boolean registeredSuffixPatternMatch = false;
|
||||
|
||||
@@ -600,11 +600,10 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||
|
||||
/**
|
||||
* Set whether to apply suffix pattern matching in PatternsRequestCondition.
|
||||
* <p>By default this is set to 'true'.
|
||||
* <p>By default this is set to 'false'.
|
||||
* @see #setRegisteredSuffixPatternMatch(boolean)
|
||||
* @deprecated as of 5.2.4. See class-level note in
|
||||
* {@link RequestMappingHandlerMapping} on the deprecation of path
|
||||
* extension config options.
|
||||
* @deprecated as of 5.2.4. See deprecation note on
|
||||
* {@link RequestMappingHandlerMapping#setUseSuffixPatternMatch(boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSuffixPatternMatch(boolean suffixPatternMatch) {
|
||||
@@ -613,9 +612,8 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||
|
||||
/**
|
||||
* Return whether to apply suffix pattern matching in PatternsRequestCondition.
|
||||
* @deprecated as of 5.2.4. See class-level note in
|
||||
* {@link RequestMappingHandlerMapping} on the deprecation of path
|
||||
* extension config options.
|
||||
* @deprecated as of 5.2.4. See deprecation note on
|
||||
* {@link RequestMappingHandlerMapping#setUseSuffixPatternMatch(boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean useSuffixPatternMatch() {
|
||||
@@ -630,8 +628,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||
* obtain the registered file extensions.
|
||||
* @deprecated as of 5.2.4. See class-level note in
|
||||
* {@link RequestMappingHandlerMapping} on the deprecation of path
|
||||
* extension config options; note also that in 5.3 the default for this
|
||||
* property switches from {@code false} to {@code true}.
|
||||
* extension config options.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setRegisteredSuffixPatternMatch(boolean registeredSuffixPatternMatch) {
|
||||
|
||||
@@ -61,7 +61,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMappi
|
||||
* <p><strong>Deprecation Note:</strong></p> In 5.2.4,
|
||||
* {@link #setUseSuffixPatternMatch(boolean) useSuffixPatternMatch} and
|
||||
* {@link #setUseRegisteredSuffixPatternMatch(boolean) useRegisteredSuffixPatternMatch}
|
||||
* are deprecated in order to discourage use of path extensions for request
|
||||
* were deprecated in order to discourage use of path extensions for request
|
||||
* mapping and for content negotiation (with similar deprecations in
|
||||
* {@link ContentNegotiationManager}). For further context, please read issue
|
||||
* <a href="https://github.com/spring-projects/spring-framework/issues/24179">#24719</a>.
|
||||
@@ -74,7 +74,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMappi
|
||||
public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping
|
||||
implements MatchableHandlerMapping, EmbeddedValueResolverAware {
|
||||
|
||||
private boolean useSuffixPatternMatch = true;
|
||||
private boolean useSuffixPatternMatch = false;
|
||||
|
||||
private boolean useRegisteredSuffixPatternMatch = false;
|
||||
|
||||
@@ -93,14 +93,13 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
/**
|
||||
* Whether to use suffix pattern match (".*") when matching patterns to
|
||||
* requests. If enabled a method mapped to "/users" also matches to "/users.*".
|
||||
* <p>The default value is {@code true}.
|
||||
* <p>By default value this is set to {@code false}.
|
||||
* <p>Also see {@link #setUseRegisteredSuffixPatternMatch(boolean)} for
|
||||
* more fine-grained control over specific suffixes to allow.
|
||||
* @deprecated as of 5.2.4. See class level comment about deprecation of
|
||||
* @deprecated as of 5.2.4. See class level note on the deprecation of
|
||||
* path extension config options. As there is no replacement for this method,
|
||||
* for the time being it's necessary to set it to {@code false}. In 5.3
|
||||
* when {@code false} becomes the default, use of this property will no
|
||||
* longer be necessary.
|
||||
* in 5.2.x it is necessary to set it to {@code false}. In 5.3 {@code false}
|
||||
* becomes the default, and use of this property is longer be necessary.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setUseSuffixPatternMatch(boolean useSuffixPatternMatch) {
|
||||
@@ -113,7 +112,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
* is generally recommended to reduce ambiguity and to avoid issues such as
|
||||
* when a "." appears in the path for other reasons.
|
||||
* <p>By default this is set to "false".
|
||||
* @deprecated as of 5.2.4. See class level comment about deprecation of
|
||||
* @deprecated as of 5.2.4. See class level note on the deprecation of
|
||||
* path extension config options.
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -191,8 +190,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
|
||||
/**
|
||||
* Whether to use registered suffixes for pattern matching.
|
||||
* @deprecated as of 5.2.4. See class-level note on the deprecation of path
|
||||
* extension config options.
|
||||
* @deprecated as of 5.2.4. See deprecation notice on
|
||||
* {@link #setUseSuffixPatternMatch(boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean useSuffixPatternMatch() {
|
||||
@@ -201,8 +200,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
|
||||
/**
|
||||
* Whether to use registered suffixes for pattern matching.
|
||||
* @deprecated as of 5.2.4. See class-level note on the deprecation of path
|
||||
* extension config options.
|
||||
* @deprecated as of 5.2.4. See deprecation notice on
|
||||
* {@link #setUseRegisteredSuffixPatternMatch(boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean useRegisteredSuffixPatternMatch() {
|
||||
|
||||
Reference in New Issue
Block a user