• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zalando / logbook / #4471

04 Mar 2024 07:51PM CUT coverage: 100.0%. Remained the same
#4471

push

web-flow
Add a warning about logbook.write.max-body-size not preventing the buffering (#1777)

3539 of 3539 relevant lines covered (100.0%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/logbook-api/src/main/java/org/zalando/logbook/DefaultHttpHeaders.java
1
package org.zalando.logbook;
2

3
import lombok.AllArgsConstructor;
4
import lombok.With;
5
import lombok.experimental.Delegate;
6

7
import java.util.AbstractMap;
8
import java.util.ArrayList;
9
import java.util.Collection;
10
import java.util.Collections;
11
import java.util.List;
12
import java.util.Map;
13
import java.util.Objects;
14
import java.util.TreeMap;
15

16
import static lombok.AccessLevel.PRIVATE;
17

18
@SuppressWarnings("deprecation") // needed because of @Delegate and @Deprecated
19
@AllArgsConstructor(access = PRIVATE)
20
final class DefaultHttpHeaders
21
        // gives us a meaningful equals, hashCode and toString
22
        extends AbstractMap<String, List<String>>
23
        implements UpdateHttpHeaders, ApplyHttpHeaders, DeleteHttpHeaders {
24

25
    static final HttpHeaders EMPTY = new DefaultHttpHeaders();
1✔
26

27
    @With
28
    private final TreeMap<String, List<String>> headers;
29

30
    private DefaultHttpHeaders() {
31
        this(new TreeMap<>(String.CASE_INSENSITIVE_ORDER));
1✔
32
    }
1✔
33

34
    @Delegate
35
    @SuppressWarnings("unused")
36
    private Map<String, List<String>> delegate() {
37
        return headers;
1✔
38
    }
39

40
    @Override
41
    public HttpHeaders update(
42
            final String name,
43
            final Collection<String> values) {
44

45
        TreeMap<String, List<String>> updatedHeaders = associate(headers, name, values);
1✔
46
        return withHeaders(updatedHeaders);
1✔
47
    }
48

49
    @Override
50
    public HttpHeaders delete(final Collection<String> names) {
51
        return withHeaders(delete(headers, names));
1✔
52
    }
53

54
    private static List<String> immutableCopy(final Collection<String> values) {
55
        return Collections.unmodifiableList(new ArrayList<>(values));
1✔
56
    }
57

58
    private static TreeMap<String, List<String>> associate(
59
            final TreeMap<String, List<String>> original,
60
            final String key,
61
            final Collection<String> value) {
62

63
        if (Objects.equals(original.get(key), value))
1✔
64
            return original;
1✔
65

66
        TreeMap<String, List<String>> tmpMap = new TreeMap<>(original);
1✔
67
        tmpMap.put(key, immutableCopy(value));
1✔
68
        return tmpMap;
1✔
69
    }
70

71
    private static TreeMap<String, List<String>> delete(
72
            final TreeMap<String, List<String>> original,
73
            final Collection<String> keys) {
74

75
        // This internally uses the comparator of the map
76
        if (Collections.disjoint(original.keySet(), keys))
1✔
77
            return original;
1✔
78

79
        TreeMap<String, List<String>> modifiedMap = new TreeMap<>(original);
1✔
80
        keys.forEach(modifiedMap::remove);
1✔
81
        return modifiedMap;
1✔
82
    }
83

84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc