1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 package software.amazon.awssdk.crt.http;
6 
7 import software.amazon.awssdk.crt.io.TlsConnectionOptions;
8 import software.amazon.awssdk.crt.http.HttpProxyOptions.HttpProxyConnectionType;
9 
10 /**
11  * This class provides access to Http proxy environment variable configuration
12  * setting
13  */
14 public class HttpProxyEnvironmentVariableSetting {
15 
16     private TlsConnectionOptions tlsConnectionOptions;
17     private HttpProxyEnvironmentVariableType environmentVariableType;
18     private HttpProxyConnectionType connectionType;
19 
20     /*
21      * Configuration for using proxy from environment variable.
22      */
23     public enum HttpProxyEnvironmentVariableType {
24 
25         /**
26          * Disable reading from environment variable for proxy.
27          */
28         DISABLED(0),
29 
30         /**
31          * Default.
32          * Enable reading from environment variable for proxy configuration, when the proxy options
33          * are not set.
34          * env HTTPS_PROXY/https_proxy will be checked when the main connection use tls.
35          * env HTTP_PROXY/http_proxy will be checked when the main connection does not use tls.
36          * The lower case version has precedence.
37          */
38         ENABLED(1);
39 
40         private int environmentVariableType;
41 
HttpProxyEnvironmentVariableType(int val)42         HttpProxyEnvironmentVariableType(int val) {
43             environmentVariableType = val;
44         }
45 
getValue()46         public int getValue() {
47             return environmentVariableType;
48         }
49     }
50 
51     /**
52      * Creates a new set of environment variable proxy setting
53      * By Default environmentVariableType is set to Enable.
54      */
HttpProxyEnvironmentVariableSetting()55     public HttpProxyEnvironmentVariableSetting() {
56         this.environmentVariableType = HttpProxyEnvironmentVariableType.ENABLED;
57         this.connectionType = HttpProxyConnectionType.Legacy;
58     }
59 
60     /**
61      * (Optional)
62      * Sets the proxy connection type. Defaults to HttpProxyConnectionType.Legacy
63      * @param connectionType what kind of connection to establish
64      */
setConnectionType(HttpProxyConnectionType connectionType)65     public void setConnectionType(HttpProxyConnectionType connectionType) {
66         this.connectionType = connectionType;
67     }
68 
69     /**
70      * @return the proxy connection type
71      */
getConnectionType()72     public HttpProxyConnectionType getConnectionType() {
73         return connectionType;
74     }
75 
76     /**
77      * @return the http proxy environment variable type
78      */
getEnvironmentVariableType()79     public HttpProxyEnvironmentVariableType getEnvironmentVariableType() {
80         return environmentVariableType;
81     }
82 
83     /**
84      * (Optional)
85      * Enable/Disable reading from environment variable for Proxy config. Defaults to Enabled
86      * @param environmentVariableType enable or disable env proxy
87      */
setEnvironmentVariableType(HttpProxyEnvironmentVariableType environmentVariableType)88     public void setEnvironmentVariableType(HttpProxyEnvironmentVariableType environmentVariableType) {
89         this.environmentVariableType = environmentVariableType;
90     }
91 
92     /**
93      * (Optional)
94      * Sets the tls connection options for the proxy connection
95      *
96      * @param tlsConnectionOptions tls connection options for the proxy connection
97      */
setTlsConnectionOptions(TlsConnectionOptions tlsConnectionOptions)98     public void setTlsConnectionOptions(TlsConnectionOptions tlsConnectionOptions) {
99         this.tlsConnectionOptions = tlsConnectionOptions;
100     }
101 
102     /**
103      * @return the tls connection options for the proxy connection
104      */
getTlsConnectionOptions()105     public TlsConnectionOptions getTlsConnectionOptions() {
106         return tlsConnectionOptions;
107     }
108 
109 }
110