1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.crtcore; 17 18 import java.util.Optional; 19 import software.amazon.awssdk.annotations.SdkProtectedApi; 20 import software.amazon.awssdk.crt.http.HttpMonitoringOptions; 21 import software.amazon.awssdk.crt.http.HttpProxyOptions; 22 import software.amazon.awssdk.crt.io.TlsContext; 23 import software.amazon.awssdk.utils.NumericUtils; 24 25 @SdkProtectedApi 26 public final class CrtConfigurationUtils { 27 CrtConfigurationUtils()28 private CrtConfigurationUtils() { 29 } 30 resolveProxy(CrtProxyConfiguration proxyConfiguration, TlsContext tlsContext)31 public static Optional<HttpProxyOptions> resolveProxy(CrtProxyConfiguration proxyConfiguration, 32 TlsContext tlsContext) { 33 if (proxyConfiguration == null) { 34 return Optional.empty(); 35 } 36 37 HttpProxyOptions clientProxyOptions = new HttpProxyOptions(); 38 39 clientProxyOptions.setHost(proxyConfiguration.host()); 40 clientProxyOptions.setPort(proxyConfiguration.port()); 41 42 if ("https".equalsIgnoreCase(proxyConfiguration.scheme())) { 43 clientProxyOptions.setTlsContext(tlsContext); 44 } 45 46 if (proxyConfiguration.username() != null && proxyConfiguration.password() != null) { 47 clientProxyOptions.setAuthorizationUsername(proxyConfiguration.username()); 48 clientProxyOptions.setAuthorizationPassword(proxyConfiguration.password()); 49 clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic); 50 } else { 51 clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.None); 52 } 53 54 return Optional.of(clientProxyOptions); 55 } 56 resolveHttpMonitoringOptions(CrtConnectionHealthConfiguration config)57 public static Optional<HttpMonitoringOptions> resolveHttpMonitoringOptions(CrtConnectionHealthConfiguration config) { 58 if (config == null) { 59 return Optional.empty(); 60 } 61 62 HttpMonitoringOptions httpMonitoringOptions = new HttpMonitoringOptions(); 63 httpMonitoringOptions.setMinThroughputBytesPerSecond(config.minimumThroughputInBps()); 64 int seconds = NumericUtils.saturatedCast(config.minimumThroughputTimeout().getSeconds()); 65 httpMonitoringOptions.setAllowableThroughputFailureIntervalSeconds(seconds); 66 return Optional.of(httpMonitoringOptions); 67 } 68 69 } 70