Proxy

public final class Proxy


Represents a proxy that can be used by CronetEngine.

How HTTP requests are sent via proxies depends on a variety of factors. For example: the type of proxy being used, the HTTP version being used, whether the request is being sent to a destination with an http or https URI scheme. Additionally, whether a tunnel through the proxy is established, or not, also depends on these factors.

Summary

Nested types

public abstract class Proxy.HttpConnectCallback

Controls tunnels established via HTTP CONNECT.

Actions that can be performed in response to onResponseReceived being called.

public abstract class Proxy.HttpConnectCallback.Request implements AutoCloseable

Represents an HTTP CONNECT request being sent to the proxy server.

@Retention(value = RetentionPolicy.SOURCE)
@IntDef(value = )
public annotation Proxy.Scheme

Schemes supported when defining a proxy.

Constants

static final int

Establish a plaintext connection to the proxy itself.

static final int

Establish a secure connection to the proxy itself.

Public methods

static @NonNull Proxy
createHttpProxy(
    @Proxy.Scheme int scheme,
    @NonNull String host,
    @IntRange(from = 0, to = 65535) int port,
    @NonNull Executor executor,
    @NonNull Proxy.HttpConnectCallback callback
)

Constructs an HTTP proxy.

Constants

SCHEME_HTTP

public static final int SCHEME_HTTP = 0

Establish a plaintext connection to the proxy itself.

SCHEME_HTTPS

public static final int SCHEME_HTTPS = 1

Establish a secure connection to the proxy itself.

Public methods

createHttpProxy

public static @NonNull Proxy createHttpProxy(
    @Proxy.Scheme int scheme,
    @NonNull String host,
    @IntRange(from = 0, to = 65535) int port,
    @NonNull Executor executor,
    @NonNull Proxy.HttpConnectCallback callback
)

Constructs an HTTP proxy.

When sending HTTP requests via an HTTP proxy, whether callback is called, or not, depends on the URI scheme of the destination:

  • For destinations with an https URI scheme, CronetEngine establishes a tunnel through the proxy. The tunnel is established via an HTTP CONNECT request. In this case callback will be called to control the HTTP CONNECT request used to establish the tunnel.
  • For destinations with an http URI scheme, CronetEngine sends an HTTP request, containing the entire URI of the destination, to the proxy. In this case callback will not be called.
Parameters
@Proxy.Scheme int scheme

Scheme that, alongside host and port, identifies this proxy.

@NonNull String host

Non-empty host that, alongside scheme and port, identifies this proxy.

@IntRange(from = 0, to = 65535) int port

Port that, alongside scheme and host, identifies this proxy. Its value must be within [0, 65535].

@NonNull Executor executor

Executor where callback will be invoked.

@NonNull Proxy.HttpConnectCallback callback

Callback that allows interacting with the HTTP CONNECT request, and its response, that CronetEngine sends to establish tunnels through the proxy.