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.CrtRuntimeException; 8 import software.amazon.awssdk.crt.io.TlsContext; 9 10 /** 11 * This class provides access to Http proxy configuration options 12 */ 13 public class HttpProxyOptions { 14 15 private String host; 16 private int port; 17 private String authUsername; 18 private String authPassword; 19 private TlsContext tlsContext; 20 private HttpProxyAuthorizationType authorizationType; 21 private HttpProxyConnectionType connectionType; 22 23 /** 24 * what kind of authentication, if any, to use when connecting to a proxy server 25 */ 26 public enum HttpProxyAuthorizationType { 27 /** 28 * No authentication 29 */ 30 None(0), 31 32 /** 33 * Basic (username and password base64 encoded) authentication 34 */ 35 Basic(1); 36 37 private int authType; 38 HttpProxyAuthorizationType(int val)39 HttpProxyAuthorizationType(int val) { 40 authType = val; 41 } 42 getValue()43 public int getValue() { 44 return authType; 45 } 46 } 47 48 /** 49 * What kind of proxy connection to establish 50 */ 51 public enum HttpProxyConnectionType { 52 /** 53 * The legacy default connection type: 54 * (1) If Tls is being used to connect to the endpoint, use tunneling 55 * (2) otherwise use forwarding 56 */ 57 Legacy(0), 58 59 /** 60 * Establish a forwarding-based connection through the proxy. It is invalid to use tls with 61 * a forwarding connection 62 */ 63 Forwarding(1), 64 65 /** 66 * Establish a tunneling-based connection through the proxy. 67 */ 68 Tunneling(2); 69 70 private int connectionType; 71 HttpProxyConnectionType(int val)72 HttpProxyConnectionType(int val) { 73 connectionType = val; 74 } 75 getValue()76 public int getValue() { 77 return connectionType; 78 } 79 80 } 81 82 /** 83 * Creates a new set of proxy options 84 * @throws CrtRuntimeException If the system is unable to allocate space for a http proxy options instance 85 */ HttpProxyOptions()86 public HttpProxyOptions() { 87 this.authorizationType = HttpProxyAuthorizationType.None; 88 this.connectionType = HttpProxyConnectionType.Legacy; 89 } 90 91 /** 92 * Sets the proxy connection type 93 * @param connectionType what kind of connection to establish 94 */ setConnectionType(HttpProxyConnectionType connectionType)95 public void setConnectionType(HttpProxyConnectionType connectionType) { 96 this.connectionType = connectionType; 97 } 98 99 /** 100 * @return the proxy connection type 101 */ getConnectionType()102 public HttpProxyConnectionType getConnectionType() { return connectionType; } 103 104 /** 105 * Sets the proxy host to connect through 106 * @param host proxy to connect through 107 */ setHost(String host)108 public void setHost(String host) { 109 this.host = host; 110 } 111 112 /** 113 * @return the proxy host to connect through 114 */ getHost()115 public String getHost() { return host; } 116 117 /** 118 * Sets the proxy port to connect through. 119 * For 32bit values exceeding Integer.MAX_VALUE use two's complement (i.e. -1 == 0xFFFFFFFF). 120 * @param port proxy port to connect through 121 */ setPort(int port)122 public void setPort(int port) { 123 this.port = port; 124 } 125 126 /** 127 * @return the proxy port to connect through. 128 * Note that two's complement is used for 32bit values exceeding 129 * Integer.MAX_VALUE (i.e. -1 == 0xFFFFFFFF). 130 */ getPort()131 public int getPort() { return port; } 132 133 /** 134 * Sets the proxy authorization type 135 * @param authorizationType what kind of authentication, if any, to use 136 */ setAuthorizationType(HttpProxyAuthorizationType authorizationType)137 public void setAuthorizationType(HttpProxyAuthorizationType authorizationType) { 138 this.authorizationType = authorizationType; 139 } 140 141 /** 142 * @return the proxy authorization type 143 */ getAuthorizationType()144 public HttpProxyAuthorizationType getAuthorizationType() { return authorizationType; } 145 146 /** 147 * Sets the username to use for authorization; only applicable to basic authentication 148 * @param username username to use with basic authentication 149 */ setAuthorizationUsername(String username)150 public void setAuthorizationUsername(String username) { 151 this.authUsername = username; 152 } 153 154 /** 155 * @return the username to use for authorization 156 */ getAuthorizationUsername()157 public String getAuthorizationUsername() { return authUsername; } 158 159 /** 160 * Sets the password to use for authorization; only applicable to basic authentication 161 * @param password password to use with basic authentication 162 */ setAuthorizationPassword(String password)163 public void setAuthorizationPassword(String password) { 164 this.authPassword = password; 165 } 166 167 /** 168 * @return the password to use for authorization 169 */ getAuthorizationPassword()170 public String getAuthorizationPassword() { return authPassword; } 171 172 /** 173 * Sets the tls context for the proxy connection 174 * @param tlsContext tls context for the proxy connection 175 */ setTlsContext(TlsContext tlsContext)176 public void setTlsContext(TlsContext tlsContext) { 177 this.tlsContext = tlsContext; 178 } 179 180 /** 181 * @return the tls context for the proxy connection 182 */ getTlsContext()183 public TlsContext getTlsContext() { return tlsContext; } 184 185 } 186