/** * @param headers headers object to adapt to include this HTTP message body. * @return adjusted headers for this HTTP message body. * The Content-Type and Content-Length headers may be modified to fit a HTTP message * containing this body. If the body is encoded, the Transfer-Encoding header will be set. */ public RawHttpHeaders headersFrom(RawHttpHeaders headers) { RawHttpHeaders.Builder builder = RawHttpHeaders.newBuilder(headers); getContentType().ifPresent(contentType -> builder.overwrite("Content-Type", contentType)); getContentLength().ifPresent(length -> builder.overwrite("Content-Length", Long.toString(length))); Optional.ofNullable(bodyDecoder).ifPresent(decoder -> { if (!decoder.getEncodings().isEmpty()) { builder.overwrite("Transfer-Encoding", String.join(",", decoder.getEncodings())); } }); return builder.build(); }
/** * @param headers headers object to adapt to include this HTTP message body. * @return adjusted headers for this HTTP message body. * The Content-Type and Content-Length headers may be modified to fit a HTTP message * containing this body. If the body is encoded, the Transfer-Encoding header will be set. */ public RawHttpHeaders headersFrom(RawHttpHeaders headers) { RawHttpHeaders.Builder builder = RawHttpHeaders.newBuilder(headers); getContentType().ifPresent(contentType -> builder.overwrite("Content-Type", contentType)); getContentLength().ifPresent(length -> builder.overwrite("Content-Length", Long.toString(length))); Optional.ofNullable(bodyDecoder).ifPresent(decoder -> { if (!decoder.getEncodings().isEmpty()) { builder.overwrite("Transfer-Encoding", String.join(",", decoder.getEncodings())); } }); 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(); }
RequestLine newRequestLine = requestLine.withHost(hostHeaderValues.iterator().next()); headers.overwrite("Host", newRequestLine.getUri().getHost()); return newRequestLine; } catch (IllegalArgumentException e) {
RequestLine newRequestLine = requestLine.withHost(hostHeaderValues.iterator().next()); headers.overwrite("Host", newRequestLine.getUri().getHost()); return newRequestLine; } catch (IllegalArgumentException 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(); }