@Override public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) { // TODO We create and build every time. Do we want to cache it instead of the service binding? return DEFAULT_CHAIN .loadService() .map(SdkHttpService::createHttpClientBuilder) .map(f -> f.buildWithDefaults(serviceDefaults)) .orElseThrow( () -> SdkClientException.builder() .message("Unable to load an HTTP implementation from any provider in the " + "chain. You must declare a dependency on an appropriate HTTP " + "implementation or pass in an SdkHttpClient explicitly to the " + "client builder.") .build()); }
/** * Finalize which sync HTTP client will be used for the created client. */ private SdkHttpClient resolveSyncHttpClient(SdkClientConfiguration config) { Validate.isTrue(config.option(SdkClientOption.SYNC_HTTP_CLIENT) == null || httpClientBuilder == null, "The httpClient and the httpClientBuilder can't both be configured."); return Either.fromNullable(config.option(SdkClientOption.SYNC_HTTP_CLIENT), httpClientBuilder) .map(e -> e.map(NonManagedSdkHttpClient::new, b -> b.buildWithDefaults(childHttpConfig()))) .orElseGet(() -> defaultHttpClientBuilder.buildWithDefaults(childHttpConfig())); }
/** * Create a {@link SdkHttpClient} with global defaults applied. This is useful for reusing an HTTP client across multiple * services. */ default SdkHttpClient build() { return buildWithDefaults(AttributeMap.empty()); }
/** * Create a {@link SdkHttpClient} without defaults applied. This is useful for reusing an HTTP client across multiple * services. */ default SdkHttpClient build() { return buildWithDefaults(AttributeMap.empty()); }