/** * Apply {@link Flux#reduce(Object, BiFunction) reduce} on the body, count * the number of bytes produced, release data buffers without writing, and * set the {@literal Content-Length} header. */ @Override public final Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { return Flux.from(body) .reduce(0, (current, buffer) -> { int next = current + buffer.readableByteCount(); DataBufferUtils.release(buffer); return next; }) .doOnNext(count -> getHeaders().setContentLength(count)) .then(); }
/** * Apply {@link Flux#reduce(Object, BiFunction) reduce} on the body, count * the number of bytes produced, release data buffers without writing, and * set the {@literal Content-Length} header. */ @Override public final Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { return Flux.from(body) .reduce(0, (current, buffer) -> { int next = current + buffer.readableByteCount(); DataBufferUtils.release(buffer); return next; }) .doOnNext(count -> getHeaders().setContentLength(count)) .then(); }
/** * Apply {@link Flux#reduce(Object, BiFunction) reduce} on the body, count * the number of bytes produced, release data buffers without writing, and * set the {@literal Content-Length} header. */ @Override public final Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { return Flux.from(body) .reduce(0, (current, buffer) -> { int next = current + buffer.readableByteCount(); DataBufferUtils.release(buffer); return next; }) .doOnNext(count -> getHeaders().setContentLength(count)) .then(); }
/** * Apply {@link Flux#reduce(Object, BiFunction) reduce} on the body, count * the number of bytes produced, release data buffers without writing, and * set the {@literal Content-Length} header. */ @Override public final Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { // After Reactor Netty #171 is fixed we can return without delegating return getDelegate().writeWith( Flux.from(body) .reduce(0, (current, buffer) -> { int next = current + buffer.readableByteCount(); DataBufferUtils.release(buffer); return next; }) .doOnNext(count -> getHeaders().setContentLength(count)) .then(Mono.empty())); }