/** * Merge this builder's headers with the ones provided. * * @param headers to merge with this builder * @return this */ public Builder merge(RawHttpHeaders headers) { headers.forEach(this::with); return this; }
/** * Merge this builder's headers with the ones provided. * * @param headers to merge with this builder * @return this */ public Builder merge(RawHttpHeaders headers) { headers.forEach(this::with); return this; }
@Override public String toString() { StringBuilder builder = new StringBuilder(); forEach((name, value) -> builder.append(name).append(": ").append(value).append("\r\n")); return builder.toString(); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); forEach((name, value) -> builder.append(name).append(": ").append(value).append("\r\n")); return builder.toString(); }
/** * Iterate over all entries in this set of headers. * <p> * The consumer is called for each value of a header. If a header has multiple values, each value is consumed * once, so the same header name (with the original case it was inserted with) may be consumed more than once. * * @param consumer accepts the header name and value * @throws IOException if the consumer throws */ public void forEachIO(IOBiConsumer<String, String> consumer) throws IOException { try { forEach((name, value) -> { try { consumer.accept(name, value); } catch (IOException e) { throw new RuntimeException(e); } }); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw e; } }
/** * Iterate over all entries in this set of headers. * <p> * The consumer is called for each value of a header. If a header has multiple values, each value is consumed * once, so the same header name (with the original case it was inserted with) may be consumed more than once. * * @param consumer accepts the header name and value * @throws IOException if the consumer throws */ public void forEachIO(IOBiConsumer<String, String> consumer) throws IOException { try { forEach((name, value) -> { try { consumer.accept(name, value); } catch (IOException e) { throw new RuntimeException(e); } }); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw e; } }
/** * Create a new set of headers, adding/replacing the provided headers into this instance. * <p> * Multi-valued headers present in both this and the provided headers are not merged. The provided headers * are guaranteed to be present and have the same values in the returned instance. * * @param headers to add or replace on this. * @return new set of headers containing both this instance's values as well as the provided values */ public RawHttpHeaders and(RawHttpHeaders headers) { Builder builder = RawHttpHeaders.newBuilderSkippingValidation(this); Set<String> visitedNames = new HashSet<>(headers.headerNames.size()); headers.forEach((name, value) -> { String key = toUppercaseAscii(name); boolean isNewKey = visitedNames.add(key); if (isNewKey) { builder.overwrite(name, value); } else { builder.with(name, value); } }); return builder.build(); }
/** * Create a new set of headers, adding/replacing the provided headers into this instance. * <p> * Multi-valued headers present in both this and the provided headers are not merged. The provided headers * are guaranteed to be present and have the same values in the returned instance. * * @param headers to add or replace on this. * @return new set of headers containing both this instance's values as well as the provided values */ public RawHttpHeaders and(RawHttpHeaders headers) { Builder builder = RawHttpHeaders.newBuilderSkippingValidation(this); Set<String> visitedNames = new HashSet<>(headers.headerNames.size()); headers.forEach((name, value) -> { String key = toUppercaseAscii(name); boolean isNewKey = visitedNames.add(key); if (isNewKey) { builder.overwrite(name, value); } else { builder.with(name, value); } }); return builder.build(); }