AbstractServerHttpResponse stores HTTP status code as integer value

Issue: SPR-16073
This commit is contained in:
Juergen Hoeller
2017-10-16 15:34:09 +02:00
parent 8a94077da0
commit 3890d4c9eb
5 changed files with 38 additions and 14 deletions

View File

@@ -62,7 +62,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
private final DataBufferFactory dataBufferFactory;
@Nullable
private HttpStatus statusCode;
private Integer statusCode;
private final HttpHeaders headers;
@@ -96,7 +96,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
return false;
}
else {
this.statusCode = statusCode;
this.statusCode = (statusCode != null ? statusCode.value() : null);
return true;
}
}
@@ -104,6 +104,25 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
@Override
@Nullable
public HttpStatus getStatusCode() {
return (this.statusCode != null ? HttpStatus.resolve(this.statusCode) : null);
}
/**
* Set the HTTP status code of the response.
* @param statusCode the HTTP status as an integer value
* @since 5.0.1
*/
public void setStatusCodeValue(Integer statusCode) {
this.statusCode = statusCode;
}
/**
* Return the HTTP status code of the response.
* @return the HTTP status as an integer value
* @since 5.0.1
*/
@Nullable
public Integer getStatusCodeValue() {
return this.statusCode;
}
@@ -121,7 +140,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
@Override
public void addCookie(ResponseCookie cookie) {
Assert.notNull(cookie, "'cookie' must not be null");
Assert.notNull(cookie, "ResponseCookie must not be null");
if (this.state.get() == State.COMMITTED) {
throw new IllegalStateException("Can't add the cookie " + cookie +

View File

@@ -32,7 +32,6 @@ import reactor.ipc.netty.http.server.HttpServerResponse;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ZeroCopyHttpOutputMessage;
import org.springframework.util.Assert;
@@ -65,9 +64,9 @@ class ReactorServerHttpResponse extends AbstractServerHttpResponse implements Ze
@Override
protected void applyStatusCode() {
HttpStatus statusCode = this.getStatusCode();
Integer statusCode = getStatusCodeValue();
if (statusCode != null) {
this.response.status(HttpResponseStatus.valueOf(statusCode.value()));
this.response.status(HttpResponseStatus.valueOf(statusCode));
}
}

View File

@@ -92,9 +92,9 @@ class ServletServerHttpResponse extends AbstractListenerServerHttpResponse {
@Override
protected void applyStatusCode() {
HttpStatus statusCode = this.getStatusCode();
Integer statusCode = getStatusCodeValue();
if (statusCode != null) {
this.response.setStatus(statusCode.value());
this.response.setStatus(statusCode);
}
}

View File

@@ -37,7 +37,6 @@ import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ZeroCopyHttpOutputMessage;
import org.springframework.lang.Nullable;
@@ -75,9 +74,9 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl
@Override
protected void applyStatusCode() {
HttpStatus statusCode = this.getStatusCode();
Integer statusCode = getStatusCodeValue();
if (statusCode != null) {
this.exchange.setStatusCode(statusCode.value());
this.exchange.setStatusCode(statusCode);
}
}