/** * Removes message body content from this request. * <p> * Transforms the content {@link ByteStream} to an empty stream such * that all received content events are discarded. * * @return {@code this} */ public Builder removeBody() { this.body = body.drop(); return this; }
/** * Replaces this {@link ByteStream} with a new {@link ByteStream}. * * Consumes this stream by safely disposing each {@link Buffer} object * and then emits {@link Buffer} objects from the provided * {@code byteStream}. * * @param byteStream a replacement byte stream. * @return a {@link ByteStream} object. */ public ByteStream replaceWith(ByteStream byteStream) { return this.drop().concat(byteStream); }
/** * Consume the message by discarding the message body. * <p> * This method reads the entire message body from the networks and black holes * all the traffic. This has the benefit of keeping the underlying TCP connection * open for connection pooling. * <p> */ default void consume() { body().drop().aggregate(1) .thenApply(buffer -> { buffer.delegate().release(); return null; }); }
@Test public void discardsContent() { ByteStream stream = new ByteStream(Flux.just(buf1, buf2, buf3)); ByteStream discarded = stream.drop(); StepVerifier.create(discarded) .expectSubscription() .verifyComplete(); assertThat(buf1.delegate().refCnt(), is(0)); assertThat(buf2.delegate().refCnt(), is(0)); assertThat(buf3.delegate().refCnt(), is(0)); }