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

ru.tinkoff.kora.http.client.jdk.JdkHttpClientModule Maven / Gradle / Ivy

There is a newer version: 1.1.16
Show newest version
package ru.tinkoff.kora.http.client.jdk;

import ru.tinkoff.kora.common.DefaultComponent;
import ru.tinkoff.kora.config.common.Config;
import ru.tinkoff.kora.config.common.ConfigValue;
import ru.tinkoff.kora.config.common.extractor.ConfigValueExtractor;
import ru.tinkoff.kora.http.client.common.HttpClientConfig;
import ru.tinkoff.kora.http.client.common.HttpClientModule;

import java.net.http.HttpClient;

public interface JdkHttpClientModule extends HttpClientModule {
    default JdkHttpClient jdkHttpClient(HttpClient client) {
        return new JdkHttpClient(client);
    }

    default JdkHttpClientConfig jdkHttpClientConfig(Config config, ConfigValueExtractor extractor) {
        return extractor.extract(config.get("httpClient.jdk"));
    }

    default ConfigValueExtractor jdkHttpClientVersionExtractor() {
        return value -> {
            if (value instanceof ConfigValue.NullValue) {
                return null;
            }
            var str = value.asString();
            return HttpClient.Version.valueOf(str);
        };
    }

    @DefaultComponent
    default JdkHttpClientWrapper jdkHttpClientWrapper(JdkHttpClientConfig config, HttpClientConfig baseConfig) {
        return new JdkHttpClientWrapper(config, baseConfig);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy