/** * Send Object to the peer, listen for any error on write and close on terminal signal * (complete|error). If more than one publisher is attached (multiple calls to send()) * completion occurs after all publishers complete. * Note: Nesting any send* method is not supported. * * @param dataStream the dataStream publishing Buffer items to write on this channel * * @return A Publisher to signal successful sequence write (e.g. after "flush") or any * error during write */ default NettyOutbound sendObject(Publisher<?> dataStream) { return then(FutureMono.disposableWriteAndFlush(context().channel(), dataStream)); }
@Override public Mono<Void> then() { ByteBufAllocator alloc = parent.channel().alloc(); return Flux.from(source) .collect(alloc::heapBuffer, ByteBuf::writeBytes) .flatMap(agg -> { if (!HttpUtil.isTransferEncodingChunked(request) && !HttpUtil.isContentLengthSet(request)) { request.headers() .setInt(HttpHeaderNames.CONTENT_LENGTH, agg.readableBytes()); } return parent.then().thenEmpty(FutureMono.disposableWriteAndFlush(context().channel(), Mono.just(agg))); }); } }