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

com.github.nhenneaux.resilienthttpclient.singlehostclient.HttpClientWrapper Maven / Gradle / Ivy

package com.github.nhenneaux.resilienthttpclient.singlehostclient;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import java.io.IOException;
import java.net.Authenticator;
import java.net.CookieHandler;
import java.net.ProxySelector;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.WebSocket;
import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Function;

public class HttpClientWrapper extends HttpClient {
    private final HttpClient httpClient;
    private final Function requestWrapper;

    HttpClientWrapper(HttpClient httpClient, Function requestWrapper) {
        this.httpClient = httpClient;
        this.requestWrapper = requestWrapper;
    }


    @Override
    public Optional cookieHandler() {
        return httpClient.cookieHandler();
    }

    @Override
    public Optional connectTimeout() {
        return httpClient.connectTimeout();
    }

    @Override
    public Redirect followRedirects() {
        return httpClient.followRedirects();
    }

    @Override
    public Optional proxy() {
        return httpClient.proxy();
    }

    @Override
    public SSLContext sslContext() {
        return httpClient.sslContext();
    }

    @Override
    public SSLParameters sslParameters() {
        return httpClient.sslParameters();
    }

    @Override
    public Optional authenticator() {
        return httpClient.authenticator();
    }

    @Override
    public Version version() {
        return httpClient.version();
    }

    @Override
    public Optional executor() {
        return httpClient.executor();
    }

    @Override
    public  HttpResponse send(HttpRequest request, HttpResponse.BodyHandler responseBodyHandler) throws IOException, InterruptedException {
        return httpClient.send(requestWrapper.apply(request), responseBodyHandler);
    }

    @Override
    public  CompletableFuture> sendAsync(HttpRequest request, HttpResponse.BodyHandler responseBodyHandler) {
        return httpClient.sendAsync(requestWrapper.apply(request), responseBodyHandler);
    }

    @Override
    public  CompletableFuture> sendAsync(HttpRequest request, HttpResponse.BodyHandler responseBodyHandler, HttpResponse.PushPromiseHandler pushPromiseHandler) {
        return httpClient.sendAsync(requestWrapper.apply(request), responseBodyHandler, pushPromiseHandler);
    }

    @Override
    public WebSocket.Builder newWebSocketBuilder() {
        return httpClient.newWebSocketBuilder();
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy