Avoid duplicate Etag/Last-Modified header values
This commit improves SPR-13090 and avoids adding duplicate ETag and Last-Modified headers in HTTP responses. Previously, those were added twice to the response since: * we're adding all ResponseEntity headers to the response * the `checkNotModified` methods automatically add those headers Issue: SPR-13090
This commit is contained in:
@@ -168,12 +168,15 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||
}
|
||||
|
||||
HttpHeaders entityHeaders = responseEntity.getHeaders();
|
||||
if (!entityHeaders.isEmpty()) {
|
||||
outputMessage.getHeaders().putAll(entityHeaders);
|
||||
}
|
||||
|
||||
Object body = responseEntity.getBody();
|
||||
if (responseEntity instanceof ResponseEntity) {
|
||||
for (String headerName : entityHeaders.keySet()) {
|
||||
if(!HttpHeaders.LAST_MODIFIED.equals(headerName)
|
||||
&& !HttpHeaders.ETAG.equals(headerName)) {
|
||||
outputMessage.getHeaders().put(headerName, entityHeaders.get(headerName));
|
||||
}
|
||||
}
|
||||
if (isResourceNotModified(webRequest, (ResponseEntity<?>) responseEntity)) {
|
||||
// Ensure headers are flushed, no body should be written.
|
||||
outputMessage.flush();
|
||||
@@ -181,6 +184,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!entityHeaders.isEmpty()) {
|
||||
outputMessage.getHeaders().putAll(entityHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
// Try even with null body. ResponseBodyAdvice could get involved.
|
||||
writeWithMessageConverters(body, returnType, inputMessage, outputMessage);
|
||||
|
||||
Reference in New Issue
Block a user