Turn off use of path extensions by default
Closes gh-23915
This commit is contained in:
@@ -50,18 +50,18 @@ import org.springframework.web.context.ServletContextAware;
|
||||
* <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>
|
||||
@@ -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<>();
|
||||
|
||||
@@ -117,7 +117,7 @@ public class ContentNegotiationManagerFactoryBean
|
||||
@Nullable
|
||||
private Boolean useRegisteredExtensionsOnly;
|
||||
|
||||
private String parameterName = "format";
|
||||
private boolean ignoreAcceptHeader = false;
|
||||
|
||||
@Nullable
|
||||
private ContentNegotiationStrategy defaultNegotiationStrategy;
|
||||
@@ -141,17 +141,35 @@ public class ContentNegotiationManagerFactoryBean
|
||||
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) {
|
||||
@@ -224,8 +242,8 @@ public class ContentNegotiationManagerFactoryBean
|
||||
/**
|
||||
* 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) {
|
||||
@@ -247,26 +265,6 @@ public class ContentNegotiationManagerFactoryBean
|
||||
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}.
|
||||
|
||||
Reference in New Issue
Block a user