ResponseEntity allows for setting non-standard status code
Issue: SPR-14205
This commit is contained in:
@@ -184,9 +184,8 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||
}
|
||||
}
|
||||
|
||||
Object body = responseEntity.getBody();
|
||||
if (responseEntity instanceof ResponseEntity) {
|
||||
outputMessage.setStatusCode(((ResponseEntity<?>) responseEntity).getStatusCode());
|
||||
outputMessage.getServletResponse().setStatus(((ResponseEntity<?>) responseEntity).getStatusCodeValue());
|
||||
HttpMethod method = inputMessage.getMethod();
|
||||
boolean isGetOrHead = (HttpMethod.GET == method || HttpMethod.HEAD == method);
|
||||
if (isGetOrHead && isResourceNotModified(inputMessage, outputMessage)) {
|
||||
@@ -197,6 +196,8 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Object body = responseEntity.getBody();
|
||||
if (inputMessage.getHeaders().containsKey(HttpHeaders.RANGE) &&
|
||||
Resource.class.isAssignableFrom(body.getClass())) {
|
||||
try {
|
||||
|
||||
@@ -130,9 +130,9 @@ public class ResponseBodyEmitterReturnValueHandler implements AsyncHandlerMethod
|
||||
HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
|
||||
ServerHttpResponse outputMessage = new ServletServerHttpResponse(response);
|
||||
|
||||
if (ResponseEntity.class.isAssignableFrom(returnValue.getClass())) {
|
||||
if (returnValue instanceof ResponseEntity) {
|
||||
ResponseEntity<?> responseEntity = (ResponseEntity<?>) returnValue;
|
||||
outputMessage.setStatusCode(responseEntity.getStatusCode());
|
||||
response.setStatus(responseEntity.getStatusCodeValue());
|
||||
outputMessage.getHeaders().putAll(responseEntity.getHeaders());
|
||||
returnValue = responseEntity.getBody();
|
||||
if (returnValue == null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.springframework.web.filter.ShallowEtagHeaderFilter;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
|
||||
/**
|
||||
* Supports return values of type
|
||||
* {@link org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody}
|
||||
@@ -68,11 +67,10 @@ public class StreamingResponseBodyReturnValueHandler implements HandlerMethodRet
|
||||
HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
|
||||
ServerHttpResponse outputMessage = new ServletServerHttpResponse(response);
|
||||
|
||||
if (ResponseEntity.class.isAssignableFrom(returnValue.getClass())) {
|
||||
if (returnValue instanceof ResponseEntity) {
|
||||
ResponseEntity<?> responseEntity = (ResponseEntity<?>) returnValue;
|
||||
outputMessage.setStatusCode(responseEntity.getStatusCode());
|
||||
response.setStatus(responseEntity.getStatusCodeValue());
|
||||
outputMessage.getHeaders().putAll(responseEntity.getHeaders());
|
||||
|
||||
returnValue = responseEntity.getBody();
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
@@ -97,7 +95,6 @@ public class StreamingResponseBodyReturnValueHandler implements HandlerMethodRet
|
||||
|
||||
private final StreamingResponseBody streamingBody;
|
||||
|
||||
|
||||
public StreamingResponseBodyTask(OutputStream outputStream, StreamingResponseBody streamingBody) {
|
||||
this.outputStream = outputStream;
|
||||
this.streamingBody = streamingBody;
|
||||
|
||||
Reference in New Issue
Block a user