/** * @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(); }