Return unique set from ContentCachingResponseWrapper.getHeaderNames()
Prior to this commit, getHeaderNames() returned duplicates for the Content-Type and Content-Length headers if they were set in the wrapped response as well as in ContentCachingResponseWrapper. This commit fixes that by returning a unique set from getHeaderNames(). In addition, this commit introduces a new test in ContentCachingResponseWrapperTests to verify the expected behavior for Content-Type and Content-Length headers that are set in the wrapped response as well as in ContentCachingResponseWrapper. See gh-32039 See gh-32317
This commit is contained in:
@@ -21,10 +21,10 @@ import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.WriteListener;
|
||||
@@ -254,7 +254,7 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
|
||||
public Collection<String> getHeaderNames() {
|
||||
Collection<String> headerNames = super.getHeaderNames();
|
||||
if (this.contentLength != null || this.contentType != null) {
|
||||
List<String> result = new ArrayList<>(headerNames);
|
||||
Set<String> result = new LinkedHashSet<>(headerNames);
|
||||
if (this.contentLength != null) {
|
||||
result.add(HttpHeaders.CONTENT_LENGTH);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user