ProxyOptions Class

  • java.lang.Object
    • com.azure.core.http.ProxyOptions

public 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 Type enum to represent the proxy type, which can be HTTP, SOCKS4, or SOCKS5.

Constructor Summary

Constructor Description
ProxyOptions(ProxyOptions.Type type, InetSocketAddress address)

Creates ProxyOptions.

Method Summary

Modifier and Type Method and Description
static ProxyOptions fromConfiguration(Configuration configuration)

Attempts to load a proxy from the configuration.

static ProxyOptions fromConfiguration(Configuration configuration, boolean createUnresolved)

Attempts to load a proxy from the environment.

InetSocketAddress getAddress()

Gets the address of the proxy.

String getNonProxyHosts()

Gets the host that bypass the proxy.

String getPassword()

Gets the proxy password.

Type getType()

Gets the type of the proxy.

String getUsername()

Gets the proxy username.

ProxyOptions setCredentials(String username, String password)

Set the proxy credentials.

ProxyOptions setNonProxyHosts(String nonProxyHosts)

Sets the hosts which bypass the proxy.

Methods inherited from java.lang.Object

Constructor Details

ProxyOptions

public ProxyOptions(ProxyOptions.Type type, InetSocketAddress address)

Creates ProxyOptions.

Parameters:

type - the proxy type
address - the proxy address (ip and port number)

Method Details

fromConfiguration

public static ProxyOptions fromConfiguration(Configuration configuration)

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:

  1. Azure HTTPS
  2. Azure HTTP
  3. Java HTTPS
  4. Java HTTP

Azure proxy configurations will be preferred over Java proxy configurations as they are more closely scoped to the purpose of the SDK. Additionally, more secure protocols, HTTPS vs HTTP, will be preferred.

null will be returned if no proxy was found in the environment.

Parameters:

configuration - The Configuration that is used to load proxy configurations from the environment. If null is passed then getGlobalConfiguration() will be used.

Returns:

A ProxyOptions reflecting a proxy loaded from the environment, if no proxy is found null will be returned.

fromConfiguration

public static ProxyOptions fromConfiguration(Configuration configuration, boolean createUnresolved)

Attempts to load a proxy from the environment.

If a proxy is found and loaded, the proxy address is DNS resolved based on createUnresolved. When createUnresolved is true resolving getAddress() may be required before using the address in network calls.

Environment configurations are loaded in this order:

  1. Azure HTTPS
  2. Azure HTTP
  3. Java HTTPS
  4. Java HTTP

Azure proxy configurations will be preferred over Java proxy configurations as they are more closely scoped to the purpose of the SDK. Additionally, more secure protocols, HTTPS vs HTTP, will be preferred.

null will be returned if no proxy was found in the environment.

Parameters:

configuration - The Configuration that is used to load proxy configurations from the environment. If null is passed then getGlobalConfiguration() will be used. If NONE is passed IllegalArgumentException will be thrown.
createUnresolved - Flag determining whether the returned ProxyOptions is unresolved.

Returns:

A ProxyOptions reflecting a proxy loaded from the environment, if no proxy is found null will be returned.

getAddress

public InetSocketAddress getAddress()

Gets the address of the proxy.

Returns:

the address of the proxy.

getNonProxyHosts

public String getNonProxyHosts()

Gets the host that bypass the proxy.

Returns:

the hosts that bypass the proxy.

getPassword

public String getPassword()

Gets the proxy password.

Returns:

the proxy password.

getType

public ProxyOptions.Type getType()

Gets the type of the proxy.

Returns:

the type of the proxy.

getUsername

public String getUsername()

Gets the proxy username.

Returns:

the proxy username.

setCredentials

public ProxyOptions setCredentials(String username, String password)

Set the proxy credentials.

Parameters:

username - proxy user name
password - proxy password

Returns:

the updated ProxyOptions object

setNonProxyHosts

public ProxyOptions setNonProxyHosts(String nonProxyHosts)

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

Applies to