|
28 | 28 | import org.springframework.core.ResolvableType;
|
29 | 29 | import org.springframework.http.HttpEntity;
|
30 | 30 | import org.springframework.http.HttpHeaders;
|
| 31 | +import org.springframework.http.HttpMethod; |
31 | 32 | import org.springframework.http.RequestEntity;
|
32 | 33 | import org.springframework.http.ResponseEntity;
|
33 | 34 | import org.springframework.http.converter.HttpMessageConverter;
|
@@ -181,16 +182,16 @@ public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
181 | 182 | }
|
182 | 183 |
|
183 | 184 | if (responseEntity instanceof ResponseEntity) {
|
184 |
| - int responseStatus = ((ResponseEntity<?>) responseEntity).getStatusCodeValue(); |
185 |
| - outputMessage.getServletResponse().setStatus(responseStatus); |
186 |
| - if(responseStatus == 200) { |
187 |
| - if (isResourceNotModified(inputMessage, outputMessage)) { |
188 |
| - // Ensure headers are flushed, no body should be written. |
189 |
| - outputMessage.flush(); |
190 |
| - // Skip call to converters, as they may update the body. |
191 |
| - return; |
192 |
| - } |
193 |
| - } |
| 185 | + int returnStatus = ((ResponseEntity<?>) responseEntity).getStatusCodeValue(); |
| 186 | + outputMessage.getServletResponse().setStatus(returnStatus); |
| 187 | + if (returnStatus == 200) { |
| 188 | + if (isResourceNotModified(inputMessage, outputMessage)) { |
| 189 | + // Ensure headers are flushed, no body should be written. |
| 190 | + outputMessage.flush(); |
| 191 | + // Skip call to converters, as they may update the body. |
| 192 | + return; |
| 193 | + } |
| 194 | + } |
194 | 195 | }
|
195 | 196 |
|
196 | 197 | // Try even with null body. ResponseBodyAdvice could get involved.
|
@@ -227,8 +228,10 @@ private boolean isResourceNotModified(ServletServerHttpRequest inputMessage, Ser
|
227 | 228 | HttpHeaders responseHeaders = outputMessage.getHeaders();
|
228 | 229 | String etag = responseHeaders.getETag();
|
229 | 230 | long lastModifiedTimestamp = responseHeaders.getLastModified();
|
230 |
| - responseHeaders.remove(HttpHeaders.ETAG); |
231 |
| - responseHeaders.remove(HttpHeaders.LAST_MODIFIED); |
| 231 | + if (inputMessage.getMethod() == HttpMethod.GET || inputMessage.getMethod() == HttpMethod.HEAD) { |
| 232 | + responseHeaders.remove(HttpHeaders.ETAG); |
| 233 | + responseHeaders.remove(HttpHeaders.LAST_MODIFIED); |
| 234 | + } |
232 | 235 |
|
233 | 236 | return servletWebRequest.checkNotModified(etag, lastModifiedTimestamp);
|
234 | 237 | }
|
|
0 commit comments