MockHttpServletRequest allows for removing registered header entries

Issue: SPR-17295
This commit is contained in:
Juergen Hoeller
2018-09-29 17:36:03 +02:00
parent e54eb56cb9
commit a21ce42558
2 changed files with 34 additions and 16 deletions

View File

@@ -101,7 +101,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
new BufferedReader(new StringReader(""));
/**
* Date formats as specified in the HTTP RFC
* Date formats as specified in the HTTP RFC.
* @see <a href="https://tools.ietf.org/html/rfc7231#section-7.1.1.1">Section 7.1.1.1 of RFC 7231</a>
*/
private static final String[] DATE_FORMATS = new String[] {
@@ -551,7 +551,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
/**
* Adds all provided parameters <strong>without</strong> replacing any
* Add all provided parameters <strong>without</strong> replacing any
* existing values. To replace existing values, use
* {@link #setParameters(java.util.Map)}.
*/
@@ -581,7 +581,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
/**
* Removes all existing parameters.
* Remove all existing parameters.
*/
public void removeAllParameters() {
this.parameters.clear();
@@ -746,8 +746,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
/**
* Set the list of preferred locales, in descending order, effectively replacing
* any existing locales.
* @see #addPreferredLocale
* @since 3.2
* @see #addPreferredLocale
*/
public void setPreferredLocales(List<Locale> locales) {
Assert.notEmpty(locales, "Locale list must not be empty");
@@ -945,9 +945,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
/**
* Add a header entry for the given name.
* <p>While this method can take any {@code Object} as a parameter, it
* is recommended to use the following types:
* Add an HTTP header entry for the given name.
* <p>While this method can take any {@code Object} as a parameter,
* it is recommended to use the following types:
* <ul>
* <li>String or any Object to be converted using {@code toString()}; see {@link #getHeader}.</li>
* <li>String, Number, or Date for date headers; see {@link #getDateHeader}.</li>
@@ -999,6 +999,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
}
/**
* Remove already registered entries for the specified HTTP header, if any.
* @since 4.3.20
*/
public void removeHeader(String name) {
Assert.notNull(name, "Header name must not be null");
this.headers.remove(name);
}
/**
* Return the long timestamp for the date header with the given {@code name}.
* <p>If the internal value representation is a String, this method will try
@@ -1232,7 +1241,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
public String changeSessionId() {
Assert.isTrue(this.session != null, "The request does not have a session");
if (this.session instanceof MockHttpSession) {
return ((MockHttpSession) session).changeSessionId();
return ((MockHttpSession) this.session).changeSessionId();
}
return this.session.getId();
}