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

no.digipost.signature.client.ApacheHttpClientConfigurer Maven / Gradle / Ivy

There is a newer version: 7.0.4
Show newest version
package no.digipost.signature.client;

import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.util.Timeout;

import java.time.Duration;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public interface ApacheHttpClientConfigurer {

    Consumer NO_CHANGES = t -> {};

    default ApacheHttpClientConfigurer configureSockets(BiConsumer timeoutSetter, Duration timeoutDuration) {
        return configure(config -> timeoutSetter.accept(config, Timeout.of(timeoutDuration)), NO_CHANGES, NO_CHANGES);
    }

    default ApacheHttpClientConfigurer configureConnections(BiConsumer timeoutSetter, Duration timeoutDuration) {
        return configure(NO_CHANGES, config -> timeoutSetter.accept(config, Timeout.of(timeoutDuration)), NO_CHANGES);
    }

    default ApacheHttpClientConfigurer configureRequests(BiConsumer timeoutSetter, Duration timeoutDuration) {
        return configure(NO_CHANGES, NO_CHANGES, config -> timeoutSetter.accept(config, Timeout.of(timeoutDuration)));
    }

    ApacheHttpClientConfigurer configure(
            Consumer socketConfig,
            Consumer connectionConfig,
            Consumer requestConfig);


    ApacheHttpClientConfigurer configure(
            Consumer httpClientCustomizer);

}