Skip to content

Commit

Permalink
Turn off use of path extensions by default
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev authored and kenny5he committed Jun 21, 2020
1 parent 0ec50ad commit 3ad80c7
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@
* <th>Enabled Or Not</th>
* </tr>
* <tr>
* <td>{@link #setFavorPathExtension favorPathExtension}</td>
* <td>true</td>
* <td>{@link PathExtensionContentNegotiationStrategy}</td>
* <td>Enabled</td>
* </tr>
* <tr>
* <td>{@link #setFavorParameter favorParameter}</td>
* <td>false</td>
* <td>{@link ParameterContentNegotiationStrategy}</td>
* <td>Off</td>
* </tr>
* <tr>
* <td>{@link #setFavorPathExtension favorPathExtension}</td>
* <td>false (as of 5.3)</td>
* <td>{@link PathExtensionContentNegotiationStrategy}</td>
* <td>Off</td>
* </tr>
* <tr>
* <td>{@link #setIgnoreAcceptHeader ignoreAcceptHeader}</td>
* <td>false</td>
* <td>{@link HeaderContentNegotiationStrategy}</td>
Expand Down Expand Up @@ -104,11 +104,11 @@ public class ContentNegotiationManagerFactoryBean
private List<ContentNegotiationStrategy> strategies;


private boolean favorPathExtension = true;

private boolean favorParameter = false;

private boolean ignoreAcceptHeader = false;
private String parameterName = "format";

private boolean favorPathExtension = true;

private Map<String, MediaType> mediaTypes = new HashMap<>();

Expand All @@ -117,7 +117,7 @@ public class ContentNegotiationManagerFactoryBean
@Nullable
private Boolean useRegisteredExtensionsOnly;

private String parameterName = "format";
private boolean ignoreAcceptHeader = false;

@Nullable
private ContentNegotiationStrategy defaultNegotiationStrategy;
Expand All @@ -141,17 +141,35 @@ public void setStrategies(@Nullable List<ContentNegotiationStrategy> strategies)
this.strategies = (strategies != null ? new ArrayList<>(strategies) : null);
}

/**
* 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 #setMediaTypes media type mappings}.
* <p>By default this is set to {@code false}.
* @see #setParameterName
*/
public void setFavorParameter(boolean favorParameter) {
this.favorParameter = favorParameter;
}

/**
* Set the query parameter name to use when {@link #setFavorParameter} is on.
* <p>The default parameter name is {@code "format"}.
*/
public void setParameterName(String parameterName) {
Assert.notNull(parameterName, "parameterName is required");
this.parameterName = parameterName;
}

/**
* 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.
* <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 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 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.
* 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 setFavorPathExtension(boolean favorPathExtension) {
Expand Down Expand Up @@ -224,8 +242,8 @@ public void setIgnoreUnknownPathExtensions(boolean ignore) {
/**
* Indicate whether to use the Java Activation Framework as a fallback option
* to map from file extensions to media types.
* @deprecated as of 5.0, in favor of {@link #setUseRegisteredExtensionsOnly(boolean)}, which
* has reverse behavior.
* @deprecated as of 5.0, in favor of {@link #setUseRegisteredExtensionsOnly(boolean)},
* which has reverse behavior.
*/
@Deprecated
public void setUseJaf(boolean useJaf) {
Expand All @@ -247,26 +265,6 @@ private boolean useRegisteredExtensionsOnly() {
return (this.useRegisteredExtensionsOnly != null && this.useRegisteredExtensionsOnly);
}

/**
* 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 #setMediaTypes media type mappings}.
* <p>By default this is set to {@code false}.
* @see #setParameterName
*/
public void setFavorParameter(boolean favorParameter) {
this.favorParameter = favorParameter;
}

/**
* Set the query parameter name to use when {@link #setFavorParameter} is on.
* <p>The default parameter name is {@code "format"}.
*/
public void setParameterName(String parameterName) {
Assert.notNull(parameterName, "parameterName is required");
this.parameterName = parameterName;
}

/**
* Whether to disable checking the 'Accept' request header.
* <p>By default this value is set to {@code false}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@
* <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>
Expand Down Expand Up @@ -123,18 +123,34 @@ public void strategies(@Nullable List<ContentNegotiationStrategy> strategies) {
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) {
Expand Down Expand Up @@ -190,9 +206,8 @@ public ContentNegotiationConfigurer replaceMediaTypes(Map<String, MediaType> med
* 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) {
Expand Down Expand Up @@ -224,27 +239,6 @@ public ContentNegotiationConfigurer useRegisteredExtensionsOnly(boolean useRegis
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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -150,9 +150,8 @@ public PathMatchConfigurer addPathPrefix(String prefix, Predicate<Class<?>> pred

/**
* 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
Expand All @@ -162,9 +161,8 @@ public Boolean isUseSuffixPatternMatch() {

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public static class BuilderConfiguration {

private boolean trailingSlashMatch = true;

private boolean suffixPatternMatch = true;
private boolean suffixPatternMatch = false;

private boolean registeredSuffixPatternMatch = false;

Expand Down Expand Up @@ -645,11 +645,10 @@ public boolean useTrailingSlashMatch() {

/**
* 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) {
Expand All @@ -658,9 +657,8 @@ public void setSuffixPatternMatch(boolean suffixPatternMatch) {

/**
* 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() {
Expand All @@ -675,8 +673,7 @@ public boolean useSuffixPatternMatch() {
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* <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 org.springframework.web.accept.ContentNegotiationManagerFactoryBean
* ContentNegotiationManagerFactoryBean}). For further context, please read issue
Expand All @@ -75,7 +75,7 @@
public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping
implements MatchableHandlerMapping, EmbeddedValueResolverAware {

private boolean useSuffixPatternMatch = true;
private boolean useSuffixPatternMatch = false;

private boolean useRegisteredSuffixPatternMatch = false;

Expand All @@ -94,14 +94,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) {
Expand All @@ -114,7 +113,7 @@ public void setUseSuffixPatternMatch(boolean useSuffixPatternMatch) {
* 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
Expand Down Expand Up @@ -192,8 +191,8 @@ public void afterPropertiesSet() {

/**
* 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() {
Expand All @@ -202,8 +201,8 @@ public boolean useSuffixPatternMatch() {

/**
* 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() {
Expand Down

0 comments on commit 3ad80c7

Please sign in to comment.