Search in sources :

Example 1 with CONTENT_LENGTH

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();
}
Also used : CONTENT_LENGTH(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) CONTENT_DISPOSITION(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_DISPOSITION) AsciiString(io.netty.util.AsciiString) NettyOutbound(reactor.ipc.netty.NettyOutbound) Random(java.util.Random) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) Map(java.util.Map) Path(java.nio.file.Path) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MULTIPART_FORM_DATA(io.netty.handler.codec.http.HttpHeaderValues.MULTIPART_FORM_DATA) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpClientRequest(reactor.ipc.netty.http.client.HttpClientRequest) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) Exceptions(reactor.core.Exceptions) Comparator(java.util.Comparator) NettyOutbound(reactor.ipc.netty.NettyOutbound) AsciiString(io.netty.util.AsciiString)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 CONTENT_DISPOSITION (io.netty.handler.codec.http.HttpHeaderNames.CONTENT_DISPOSITION)1 CONTENT_LENGTH (io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH)1 CONTENT_TYPE (io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE)1 MULTIPART_FORM_DATA (io.netty.handler.codec.http.HttpHeaderValues.MULTIPART_FORM_DATA)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1 AsciiString (io.netty.util.AsciiString)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Consumer (java.util.function.Consumer)1