Skip to content

Commit

Permalink
Add check to prevent redundant values in headers when using GZIPOutIn…
Browse files Browse the repository at this point in the history
…terceptor (#1819)

* Add check to prevent redundant values in headers when using GZIPOutInterceptor

* Simplify GZIPOutInterceptor#addHeader
  • Loading branch information
yvrng authored Apr 20, 2024
1 parent dc08a73 commit e4f6a6d
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,14 @@ public void thresholdReached() throws IOException {
* @param value the value to add
*/
private static void addHeader(Message message, String name, String value) {
Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?, ?>)message
.get(Message.PROTOCOL_HEADERS));
if (protocolHeaders == null) {
protocolHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
message.put(Message.PROTOCOL_HEADERS, protocolHeaders);
Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
if (headers == null) {
headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
message.put(Message.PROTOCOL_HEADERS, headers);
}
List<String> header = CastUtils.cast((List<?>)protocolHeaders.get(name));
if (header == null) {
header = new ArrayList<>();
protocolHeaders.put(name, header);
}
if (header.isEmpty()) {
List<String> header = headers.computeIfAbsent(name, k -> new ArrayList<>());
if (header.isEmpty() || !header.contains(value)) {
header.add(value);
} else {
header.set(0, header.get(0) + "," + value);
}
}
public void setForce(boolean force) {
Expand Down

0 comments on commit e4f6a6d

Please sign in to comment.