use of io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH in project cf-java-client by cloudfoundry.
the class MultipartHttpClientRequest method done.
public Mono<Void> done() {
AsciiString boundary = generateMultipartBoundary();
AsciiString delimiter = getDelimiter(boundary);
AsciiString closeDelimiter = getCloseDelimiter(boundary);
List<PartHttpClientRequest> parts = this.partConsumers.stream().map(partConsumer -> {
PartHttpClientRequest part = new PartHttpClientRequest(this.objectMapper);
partConsumer.accept(part);
return part;
}).collect(Collectors.toList());
Long contentLength = parts.stream().mapToLong(part -> delimiter.length() + CRLF.length() + part.getLength()).sum() + closeDelimiter.length();
NettyOutbound intermediateRequest = this.request.chunkedTransfer(false).header(CONTENT_TYPE, BOUNDARY_PREAMBLE.concat(boundary)).header(CONTENT_LENGTH, String.valueOf(contentLength));
for (PartHttpClientRequest part : parts) {
intermediateRequest = intermediateRequest.sendObject(Unpooled.wrappedBuffer(delimiter.toByteArray()));
intermediateRequest = intermediateRequest.sendObject(Unpooled.wrappedBuffer(CRLF.toByteArray()));
intermediateRequest = intermediateRequest.sendObject(part.renderedHeaders);
intermediateRequest = part.sendPayload(intermediateRequest);
}
intermediateRequest = intermediateRequest.sendObject(Unpooled.wrappedBuffer(closeDelimiter.toByteArray()));
return intermediateRequest.then();
}
Aggregations