Skip to content

Commit

Permalink
Simplify GZIPOutInterceptor#addHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
yvrng committed Apr 20, 2024
1 parent 4edc59c commit 21356ac
Showing 1 changed file with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,24 +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 {
String existingValue = header.get(0);
if (!existingValue.contains(value)) {
header.set(0, existingValue + "," + value);
}
}
}
public void setForce(boolean force) {
Expand Down

0 comments on commit 21356ac

Please sign in to comment.