Polishing and minor refactoring
See gh-24635
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -21,10 +21,8 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -70,8 +68,6 @@ import org.springframework.web.servlet.support.RequestContextUtils;
|
||||
*/
|
||||
public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodProcessor {
|
||||
|
||||
private static final Set<HttpMethod> SAFE_METHODS = EnumSet.of(HttpMethod.GET, HttpMethod.HEAD);
|
||||
|
||||
/**
|
||||
* Basic constructor with converters only. Suitable for resolving
|
||||
* {@code HttpEntity}. For handling {@code ResponseEntity} consider also
|
||||
@@ -205,12 +201,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||
int returnStatus = ((ResponseEntity<?>) responseEntity).getStatusCodeValue();
|
||||
outputMessage.getServletResponse().setStatus(returnStatus);
|
||||
if (returnStatus == 200) {
|
||||
if (SAFE_METHODS.contains(inputMessage.getMethod())
|
||||
HttpMethod method = inputMessage.getMethod();
|
||||
if ((HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method))
|
||||
&& isResourceNotModified(inputMessage, outputMessage)) {
|
||||
// Ensure headers are flushed, no body should be written.
|
||||
outputMessage.flush();
|
||||
ShallowEtagHeaderFilter.disableContentCaching(inputMessage.getServletRequest());
|
||||
// Skip call to converters, as they may update the body.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user