• 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/ApplyHttpHeaders.java
1
package org.zalando.logbook;
2

3
import com.google.gag.annotation.remark.ThisWouldBeOneLineIn;
4

5
import javax.annotation.Nullable;
6
import java.util.Collection;
7
import java.util.List;
8
import java.util.function.BiFunction;
9
import java.util.function.BiPredicate;
10
import java.util.function.UnaryOperator;
11

12
import static java.util.Collections.singleton;
13
import static org.zalando.logbook.Fold.fold;
14

15
interface ApplyHttpHeaders extends HttpHeaders {
16

17
    @Override
18
    default HttpHeaders apply(
19
            final String name,
20
            final UnaryOperator<List<String>> operator) {
21
        return apply(singleton(name), (ignored, previous) ->
1✔
22
                operator.apply(previous));
1✔
23
    }
24

25
    @Override
26
    default HttpHeaders apply(
27
            final Collection<String> names,
28
            final BiFunction<String, List<String>, Collection<String>> operator) {
29

30
        final HttpHeaders self = this;
1✔
31
        return fold(names, self, (result, name) -> {
1✔
32
            final List<String> previous = get(name);
1✔
33
            return applyTo(operator, name, previous, result);
1✔
34
        });
35
    }
36

37
    @Override
38
    default HttpHeaders apply(
39
            final BiPredicate<String, List<String>> predicate,
40
            final BiFunction<String, List<String>, Collection<String>> operator) {
41

42
        return apply((name, previous) -> {
1✔
43
            if (predicate.test(name, previous)) {
1✔
44
                return operator.apply(name, previous);
1✔
45
            }
46
            return previous;
1✔
47
        });
48
    }
49

50
    @Override
51
    default HttpHeaders apply(
52
            final BiFunction<String, List<String>, Collection<String>> operator) {
53

54
        final HttpHeaders self = this;
1✔
55
        return fold(entrySet(), self, (result, entry) -> {
1✔
56
            final String name = entry.getKey();
1✔
57
            final List<String> previous = entry.getValue();
1✔
58
            return applyTo(operator, name, previous, result);
1✔
59
        });
60
    }
61

62
    // Effectively package-private because this interface is and so are all
63
    // implementations of it. Ideally it would be private
64
    @ThisWouldBeOneLineIn(language = "Java 9", toWit = "private")
65
    default HttpHeaders applyTo(
66
            final BiFunction<String, List<String>, Collection<String>> operator,
67
            final String name,
68
            final List<String> previous,
69
            final HttpHeaders headers) {
70

71
        @Nullable final Collection<String> next =
1✔
72
                operator.apply(name, previous);
1✔
73

74
        return next == null ?
1✔
75
                headers.delete(name) :
1✔
76
                headers.update(name, next);
1✔
77
    }
78

79
}
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