All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zalando.logbook.spring.webflux.BufferingClientHttpRequest Maven / Gradle / Ivy

The newest version!
package org.zalando.logbook.spring.webflux;

import org.reactivestreams.Publisher;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.http.client.reactive.ClientHttpRequestDecorator;
import reactor.core.publisher.Mono;

@SuppressWarnings({"NullableProblems"})
final class BufferingClientHttpRequest extends ClientHttpRequestDecorator {
    private final ClientRequest clientRequest;

    BufferingClientHttpRequest(ClientHttpRequest delegate, ClientRequest clientRequest) {
        super(delegate);
        this.clientRequest = clientRequest;
    }

    @Override
    public Mono writeWith(Publisher body) {
        return super.writeWith(bufferingWrap(body));
    }

    private Publisher bufferingWrap(Publisher body) {
        if (clientRequest.shouldBuffer()) {
            return DataBufferCopyUtils.wrapAndBuffer(body, clientRequest::buffer);
        } else {
            return body;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy