Class ProxyOptions
Represents the proxy configuration to be used in HTTP clients.
This class encapsulates the proxy settings, including the proxy type, address, and optional credentials. It provides methods to set and get these properties.
This class is useful when you want to configure a proxy for an HTTP client. For example, you can use it to create a proxy with specific credentials, or to specify hosts that should bypass the proxy.
Note: This class provides a ProxyOptions.Type enum to represent the proxy type, which can be HTTP, SOCKS4, or SOCKS5.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionProxyOptions(ProxyOptions.Type type, InetSocketAddress address) Creates ProxyOptions. -
Method Summary
Modifier and TypeMethodDescriptionstatic ProxyOptionsfromConfiguration(Configuration configuration) Attempts to load a proxy from the configuration.static ProxyOptionsfromConfiguration(Configuration configuration, boolean createUnresolved) Attempts to load a proxy from the environment.Gets the address of the proxy.Gets the host that bypass the proxy.Gets the proxy password.getType()Gets the type of the proxy.Gets the proxy username.setCredentials(String username, String password) Set the proxy credentials.setNonProxyHosts(String nonProxyHosts) Sets the hosts which bypass the proxy.
-
Constructor Details
-
ProxyOptions
Creates ProxyOptions.- Parameters:
type- the proxy typeaddress- the proxy address (ip and port number)
-
-
Method Details
-
setCredentials
Set the proxy credentials.- Parameters:
username- proxy user namepassword- proxy password- Returns:
- the updated ProxyOptions object
-
setNonProxyHosts
Sets the hosts which bypass the proxy.The expected format of the passed string is a
'|'delimited list of hosts which should bypass the proxy. Individual host strings may contain regex characters such as'*'.- Parameters:
nonProxyHosts- Hosts that bypass the proxy.- Returns:
- the updated ProxyOptions object
-
getAddress
Gets the address of the proxy.- Returns:
- the address of the proxy.
-
getType
Gets the type of the proxy.- Returns:
- the type of the proxy.
-
getUsername
Gets the proxy username.- Returns:
- the proxy username.
-
getPassword
Gets the proxy password.- Returns:
- the proxy password.
-
getNonProxyHosts
Gets the host that bypass the proxy.- Returns:
- the hosts that bypass the proxy.
-
fromConfiguration
Attempts to load a proxy from the configuration.If a proxy is found and loaded the proxy address is DNS resolved.
Environment configurations are loaded in this order:
- Azure HTTPS
- Azure HTTP
- Java HTTPS
- Java HTTP
nullwill be returned if no proxy was found in the environment.- Parameters:
configuration- TheConfigurationthat is used to load proxy configurations from the environment. Ifnullis passed thenConfiguration.getGlobalConfiguration()will be used.- Returns:
- A
ProxyOptionsreflecting a proxy loaded from the environment, if no proxy is foundnullwill be returned.
-
fromConfiguration
Attempts to load a proxy from the environment.If a proxy is found and loaded, the proxy address is DNS resolved based on
createUnresolved. WhencreateUnresolvedis true resolvinggetAddress()may be required before using the address in network calls.Environment configurations are loaded in this order:
- Azure HTTPS
- Azure HTTP
- Java HTTPS
- Java HTTP
nullwill be returned if no proxy was found in the environment.- Parameters:
configuration- TheConfigurationthat is used to load proxy configurations from the environment. Ifnullis passed thenConfiguration.getGlobalConfiguration()will be used. IfConfiguration.NONEis passedIllegalArgumentExceptionwill be thrown.createUnresolved- Flag determining whether the returnedProxyOptionsis unresolved.- Returns:
- A
ProxyOptionsreflecting a proxy loaded from the environment, if no proxy is foundnullwill be returned.
-