HeaderLogParam implements LogParam { @Override public void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength) { if (maskedFields.contains(header.toString())) { builder.append("******"); } else if (values.size() == 1) { builder.append(values.getFirst()); } else { builder.append(Arrays.toString(values.toArray())); } } HeaderLogParam(HttpString header, HeaderValues values); @Override void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength);  }
@Test void appendWithMask() { var headers = new HeaderMap(); HttpString name = new HttpString("SessionId"); headers.put(name, "value"); var param = new HeaderLogParam(name, headers.get(name)); var builder = new StringBuilder(); param.append(builder, Set.of("SessionId"), 1000); assertThat(builder.toString()).isEqualTo("******"); }
@Test void append() { var headers = new HeaderMap(); HttpString name = new HttpString("client-id"); headers.put(name, "client1"); var builder = new StringBuilder(); var param = new HeaderLogParam(name, headers.get(name)); param.append(builder, Set.of(), 1000); assertThat(builder.toString()).isEqualTo("client1"); headers.add(name, "client2"); builder = new StringBuilder(); param = new HeaderLogParam(name, headers.get(name)); param.append(builder, Set.of(), 1000); assertThat(builder.toString()).isEqualTo("[client1, client2]"); }