Skip to content

Commit cfb29db

Browse files
committed
Initial support for Servlet 6.1
Closes gh-31159
1 parent 570c5b3 commit cfb29db

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

Diff for: spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,15 @@ public void sendError(int status) throws IOException {
623623

624624
@Override
625625
public void sendRedirect(String url) throws IOException {
626+
sendRedirect(url, HttpServletResponse.SC_MOVED_TEMPORARILY, true);
627+
}
628+
629+
// @Override - on Servlet 6.1
630+
public void sendRedirect(String url, int sc, boolean clearBuffer) throws IOException {
626631
Assert.state(!isCommitted(), "Cannot send redirect - response is already committed");
627632
Assert.notNull(url, "Redirect URL must not be null");
628633
setHeader(HttpHeaders.LOCATION, url);
629-
setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
634+
setStatus(sc);
630635
setCommitted(true);
631636
}
632637

@@ -775,7 +780,7 @@ private void setCookie(Cookie cookie) {
775780

776781
@Override
777782
public void setStatus(int status) {
778-
if (!this.isCommitted()) {
783+
if (!isCommitted()) {
779784
this.status = status;
780785
}
781786
}

Diff for: spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void setCharacterEncodingNull() {
201201
response.setCharacterEncoding("UTF-8");
202202
assertThat(response.getContentType()).isEqualTo("test/plain;charset=UTF-8");
203203
assertThat(response.getHeader(CONTENT_TYPE)).isEqualTo("test/plain;charset=UTF-8");
204-
response.setCharacterEncoding(null);
204+
response.setCharacterEncoding((String) null);
205205
assertThat(response.getContentType()).isEqualTo("test/plain");
206206
assertThat(response.getHeader(CONTENT_TYPE)).isEqualTo("test/plain");
207207
assertThat(response.getCharacterEncoding()).isEqualTo(WebUtils.DEFAULT_CHARACTER_ENCODING);

Diff for: spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,15 @@ public void sendError(int status) throws IOException {
623623

624624
@Override
625625
public void sendRedirect(String url) throws IOException {
626+
sendRedirect(url, HttpServletResponse.SC_MOVED_TEMPORARILY, true);
627+
}
628+
629+
// @Override - on Servlet 6.1
630+
public void sendRedirect(String url, int sc, boolean clearBuffer) throws IOException {
626631
Assert.state(!isCommitted(), "Cannot send redirect - response is already committed");
627632
Assert.notNull(url, "Redirect URL must not be null");
628633
setHeader(HttpHeaders.LOCATION, url);
629-
setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
634+
setStatus(sc);
630635
setCommitted(true);
631636
}
632637

@@ -775,7 +780,7 @@ private void setCookie(Cookie cookie) {
775780

776781
@Override
777782
public void setStatus(int status) {
778-
if (!this.isCommitted()) {
783+
if (!isCommitted()) {
779784
this.status = status;
780785
}
781786
}
@@ -785,6 +790,9 @@ public int getStatus() {
785790
return this.status;
786791
}
787792

793+
/**
794+
* Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}.
795+
*/
788796
@Nullable
789797
public String getErrorMessage() {
790798
return this.errorMessage;

Diff for: spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java

+5
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,11 @@ public void sendRedirect(String location) throws IOException {
679679
throw new UnsupportedOperationException();
680680
}
681681

682+
// @Override - on Servlet 6.1
683+
public void sendRedirect(String location, int sc, boolean clearBuffer) throws IOException {
684+
throw new UnsupportedOperationException();
685+
}
686+
682687
@Override
683688
public void addDateHeader(String name, long date) {
684689
throw new UnsupportedOperationException();

0 commit comments

Comments
 (0)