@SuppressWarnings("UnnecessaryBoxing") @Test public void replaceHeaderValue_noReplacementIfSameValue() throws Exception { Multimap<String, Long> headers = ArrayListMultimap.create(); long stamp = System.currentTimeMillis(); Long val1 = new Long(stamp); Long val2 = new Long(stamp); headers.put("a", val1); headers.put("b", 0L); HarBridgeEntryParser.replaceHeaders(headers, "a", val2); assertSame(val1, headers.get("a").iterator().next()); assertFalse(headers.get("b").isEmpty()); }
protected static <V> void replaceHeaders(Multimap<String, V> headers, String headerName, @Nullable V value) { Set<String> caseSensitiveKeys = headers.keySet().stream() .filter(headerName::equalsIgnoreCase) .collect(Collectors.toSet()); if (value != null && caseSensitiveKeys.size() == 1) { Collection<V> vals = headers.get(caseSensitiveKeys.iterator().next()); if (vals.size() == 1) { if (value.equals(vals.iterator().next())) { return; } } } caseSensitiveKeys.forEach(headers::removeAll); if (value != null) { headers.put(headerName, value); } }
HarBridgeEntryParser implements EntryParser<E> { protected static <V> void replaceHeaders(Multimap<String, V> headers, String headerName, @Nullable V value) { Set<String> caseSensitiveKeys = headers.keySet().stream() .filter(headerName::equalsIgnoreCase) .collect(Collectors.toSet()); if (value != null && caseSensitiveKeys.size() == 1) { Collection<V> vals = headers.get(caseSensitiveKeys.iterator().next()); if (vals.size() == 1) { if (value.equals(vals.iterator().next())) { return; } } } caseSensitiveKeys.forEach(headers::removeAll); if (value != null) { headers.put(headerName, value); } } }
HarBridgeEntryParser implements EntryParser<E> { protected static <V> void replaceHeaders(Multimap<String, V> headers, String headerName, @Nullable V value) { Set<String> caseSensitiveKeys = headers.keySet().stream() .filter(headerName::equalsIgnoreCase) .collect(Collectors.toSet()); if (value != null && caseSensitiveKeys.size() == 1) { Collection<V> vals = headers.get(caseSensitiveKeys.iterator().next()); if (vals.size() == 1) { if (value.equals(vals.iterator().next())) { return; } } } caseSensitiveKeys.forEach(headers::removeAll); if (value != null) { headers.put(headerName, value); } } HarBridgeEntryParser(HarBridge<E> bridge, HarResponseEncoderFactory<E> responseEncoderFactory); }
HarBridgeEntryParser implements EntryParser<E> { protected static <V> void replaceHeaders(Multimap<String, V> headers, String headerName, @Nullable V value) { Set<String> caseSensitiveKeys = headers.keySet().stream() .filter(headerName::equalsIgnoreCase) .collect(Collectors.toSet()); if (value != null && caseSensitiveKeys.size() == 1) { Collection<V> vals = headers.get(caseSensitiveKeys.iterator().next()); if (vals.size() == 1) { if (value.equals(vals.iterator().next())) { return; } } } caseSensitiveKeys.forEach(headers::removeAll); if (value != null) { headers.put(headerName, value); } } HarBridgeEntryParser(HarBridge<E> bridge, HarResponseEncoderFactory<E> responseEncoderFactory); static HarBridgeEntryParser<E> withPlainEncoder(HarBridge<E> bridge); @Override ParsedRequest parseRequest(E harEntry); @Nullable Multimap<String, Optional<String>> parseQuery(URI uri); @Override HttpRespondable parseResponse(ParsedRequest request, E entry); }
HarBridgeEntryParser implements EntryParser<E> { protected static <V> void replaceHeaders(Multimap<String, V> headers, String headerName, @Nullable V value) { Set<String> caseSensitiveKeys = headers.keySet().stream() .filter(headerName::equalsIgnoreCase) .collect(Collectors.toSet()); if (value != null && caseSensitiveKeys.size() == 1) { Collection<V> vals = headers.get(caseSensitiveKeys.iterator().next()); if (vals.size() == 1) { if (value.equals(vals.iterator().next())) { return; } } } caseSensitiveKeys.forEach(headers::removeAll); if (value != null) { headers.put(headerName, value); } } HarBridgeEntryParser(HarBridge<E> bridge, HarResponseEncoderFactory<E> responseEncoderFactory); static HarBridgeEntryParser<E> withPlainEncoder(HarBridge<E> bridge); @Override ParsedRequest parseRequest(E harEntry); @Nullable Multimap<String, Optional<String>> parseQuery(URI uri); @Override HttpRespondable parseResponse(ParsedRequest request, E entry);  }