Initial support for Servlet 6.1

Closes gh-31159
This commit is contained in:
Juergen Hoeller 2024-02-28 18:54:36 +01:00
parent 570c5b34e6
commit cfb29db278
4 changed files with 23 additions and 5 deletions

View File

@ -623,10 +623,15 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
public void sendRedirect(String url) throws IOException {
sendRedirect(url, HttpServletResponse.SC_MOVED_TEMPORARILY, true);
}
// @Override - on Servlet 6.1
public void sendRedirect(String url, int sc, boolean clearBuffer) throws IOException {
Assert.state(!isCommitted(), "Cannot send redirect - response is already committed");
Assert.notNull(url, "Redirect URL must not be null");
setHeader(HttpHeaders.LOCATION, url);
setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
setStatus(sc);
setCommitted(true);
}
@ -775,7 +780,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
public void setStatus(int status) {
if (!this.isCommitted()) {
if (!isCommitted()) {
this.status = status;
}
}

View File

@ -201,7 +201,7 @@ class MockHttpServletResponseTests {
response.setCharacterEncoding("UTF-8");
assertThat(response.getContentType()).isEqualTo("test/plain;charset=UTF-8");
assertThat(response.getHeader(CONTENT_TYPE)).isEqualTo("test/plain;charset=UTF-8");
response.setCharacterEncoding(null);
response.setCharacterEncoding((String) null);
assertThat(response.getContentType()).isEqualTo("test/plain");
assertThat(response.getHeader(CONTENT_TYPE)).isEqualTo("test/plain");
assertThat(response.getCharacterEncoding()).isEqualTo(WebUtils.DEFAULT_CHARACTER_ENCODING);

View File

@ -623,10 +623,15 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
public void sendRedirect(String url) throws IOException {
sendRedirect(url, HttpServletResponse.SC_MOVED_TEMPORARILY, true);
}
// @Override - on Servlet 6.1
public void sendRedirect(String url, int sc, boolean clearBuffer) throws IOException {
Assert.state(!isCommitted(), "Cannot send redirect - response is already committed");
Assert.notNull(url, "Redirect URL must not be null");
setHeader(HttpHeaders.LOCATION, url);
setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
setStatus(sc);
setCommitted(true);
}
@ -775,7 +780,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
public void setStatus(int status) {
if (!this.isCommitted()) {
if (!isCommitted()) {
this.status = status;
}
}
@ -785,6 +790,9 @@ public class MockHttpServletResponse implements HttpServletResponse {
return this.status;
}
/**
* Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}.
*/
@Nullable
public String getErrorMessage() {
return this.errorMessage;

View File

@ -679,6 +679,11 @@ class DefaultServerRequest implements ServerRequest {
throw new UnsupportedOperationException();
}
// @Override - on Servlet 6.1
public void sendRedirect(String location, int sc, boolean clearBuffer) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void addDateHeader(String name, long date) {
throw new UnsupportedOperationException();