HttpConnectCallback


interface HttpConnectCallback
android.net.http.Proxy.HttpConnectCallback

Controls tunnels established via HTTP CONNECT. All methods will be invoked onto the Executor specified in createHttpProxy.

Methods within this class are invoked only when HttpEngine must establish a tunnel through the proxy. Refer to createHttpProxy's documentation to understand when that is the case.

Summary

Nested classes

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

Constants
static Int

Closes the tunnel connection, preventing it from being used to send HTTP requests.

static Int

Proceeds establishing a tunnel.

Public methods
abstract Unit

Called before sending an HTTP CONNECT request to the proxy to establish a tunnel.

abstract Int
onResponseReceived(responseHeaders: MutableList<Pair<String!, String!>!>, statusCode: Int)

Called after receiving a response to the HTTP CONNECT request sent to the proxy to establish a tunnel.

Constants

RESPONSE_ACTION_CLOSE

static val RESPONSE_ACTION_CLOSE: Int

Closes the tunnel connection, preventing it from being used to send HTTP requests.

When a tunnel connection is closed, HttpEngine will interpret it as a failure to use the associated Proxy. HttpEngine will then try the next Proxy in the list passed to ProxyOptions (refer to that class documentation for more info).

Value: 0

RESPONSE_ACTION_PROCEED

static val RESPONSE_ACTION_PROCEED: Int

Proceeds establishing a tunnel.

This does not guarantee that the tunnel will successfully be established and used to send HTTP requests: HttpEngine will perform additional checks prior to that. Depending on their outcome, HttpEngine might still decide to close the tunnel connection. If the tunnel connection ends up being closed by HttpEngine, it will be considered as a failure to use the associated Proxy. HttpEngine will then try the next Proxy in the list passed to ProxyOptions (refer to that class documentation for more info)

Value: 1

Public methods

onBeforeRequest

abstract fun onBeforeRequest(request: Proxy.HttpConnectCallback.Request): Unit

Called before sending an HTTP CONNECT request to the proxy to establish a tunnel.

Allows manipulating, or canceling, said request before sending it to the proxy. Refer to Request to learn how a request can be manipulated/canceled.

Parameters
request Proxy.HttpConnectCallback.Request: Represents the HTTP CONNECT request that will be sent to the proxy.
This value cannot be null.

onResponseReceived

abstract fun onResponseReceived(
    responseHeaders: MutableList<Pair<String!, String!>!>,
    statusCode: Int
): Int

Called after receiving a response to the HTTP CONNECT request sent to the proxy to establish a tunnel. Allows reading headers and status code.

This method must return before any HTTP request can be sent via the tunnel that is being established.

This method will not be called for HTTP requests that will go through the tunnel once it is established.

If this method throws any java.lang.Throwable, the fate of the tunnel will be as if RESPONSE_ACTION_CLOSE had been returned. The java.lang.Throwable will not be caught.

Parameters
responseHeaders MutableList<Pair<String!, String!>!>: The list of headers contained in the response to the HTTP CONNECT request.
This value cannot be null.
statusCode Int: The HTTP status code contained in the response to the HTTP CONNECT request.
Return
Int A android.net.http.Proxy.HttpConnectCallback.OnResponseReceivedAction value representing what should be done with this tunnel connection. Refer to android.net.http.Proxy.HttpConnectCallback.OnResponseReceivedAction documentation.
Value is one of the following: