AbstractServerHttpResponse stores HTTP status code as integer value
Issue: SPR-16073
This commit is contained in:
		
							parent
							
								
									8a94077da0
								
							
						
					
					
						commit
						3890d4c9eb
					
				| 
						 | 
				
			
			@ -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 +
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,8 @@ import org.springframework.http.HttpStatus;
 | 
			
		|||
import org.springframework.http.RequestEntity;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.http.codec.HttpMessageWriter;
 | 
			
		||||
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
 | 
			
		||||
import org.springframework.http.server.reactive.ServerHttpResponse;
 | 
			
		||||
import org.springframework.lang.Nullable;
 | 
			
		||||
import org.springframework.util.Assert;
 | 
			
		||||
import org.springframework.web.reactive.HandlerResult;
 | 
			
		||||
| 
						 | 
				
			
			@ -48,8 +50,7 @@ import org.springframework.web.server.ServerWebExchange;
 | 
			
		|||
 * @author Rossen Stoyanchev
 | 
			
		||||
 * @since 5.0
 | 
			
		||||
 */
 | 
			
		||||
public class ResponseEntityResultHandler extends AbstractMessageWriterResultHandler
 | 
			
		||||
		implements HandlerResultHandler {
 | 
			
		||||
public class ResponseEntityResultHandler extends AbstractMessageWriterResultHandler implements HandlerResultHandler {
 | 
			
		||||
 | 
			
		||||
	private static final List<HttpMethod> SAFE_METHODS = Arrays.asList(HttpMethod.GET, HttpMethod.HEAD);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -139,7 +140,13 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand
 | 
			
		|||
 | 
			
		||||
			if (httpEntity instanceof ResponseEntity) {
 | 
			
		||||
				ResponseEntity<?> responseEntity = (ResponseEntity<?>) httpEntity;
 | 
			
		||||
				exchange.getResponse().setStatusCode(responseEntity.getStatusCode());
 | 
			
		||||
				ServerHttpResponse response = exchange.getResponse();
 | 
			
		||||
				if (response instanceof AbstractServerHttpResponse) {
 | 
			
		||||
					((AbstractServerHttpResponse) response).setStatusCodeValue(responseEntity.getStatusCodeValue());
 | 
			
		||||
				}
 | 
			
		||||
				else {
 | 
			
		||||
					response.setStatusCode(responseEntity.getStatusCode());
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			HttpHeaders entityHeaders = httpEntity.getHeaders();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue