Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 22](https://developer.android.com/sdkExtensions)

# Proxy.HttpConnectCallback

*** ** * ** ***


`
public
static


interface
Proxy.HttpConnectCallback
`


`


`

|---|
| android.net.http.Proxy.HttpConnectCallback |

<br />

*** ** * ** ***

Controls tunnels established via HTTP CONNECT. All methods will be invoked onto the Executor
specified in `https://developer.android.com/reference/android/net/http/Proxy#createHttpProxy(int,%20java.lang.String,%20int,%20java.util.concurrent.Executor,%20android.net.http.Proxy.HttpConnectCallback)`.

Methods within this class are invoked only when HttpEngine must establish a tunnel through
the proxy. Refer to `https://developer.android.com/reference/android/net/http/Proxy#createHttpProxy(int,%20java.lang.String,%20int,%20java.util.concurrent.Executor,%20android.net.http.Proxy.HttpConnectCallback)`'s documentation to understand when that is the
case.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback.Request` Represents an HTTP CONNECT request being sent to the proxy server. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback#RESPONSE_ACTION_CLOSE` Closes the tunnel connection, preventing it from being used to send HTTP requests. |
| `int` | `https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback#RESPONSE_ACTION_PROCEED` Proceeds establishing a tunnel. |

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback#onBeforeRequest(android.net.http.Proxy.HttpConnectCallback.Request)(https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback.Request request) ` Called before sending an HTTP CONNECT request to the proxy to establish a tunnel. |
| ` abstract int` | ` https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback#onResponseReceived(java.util.List<android.util.Pair<java.lang.String,java.lang.String>>,%20int)(https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/util/Pair<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/java/lang/String>> responseHeaders, int statusCode) ` Called after receiving a response to the HTTP CONNECT request sent to the proxy to establish a tunnel. |

## Constants

### RESPONSE_ACTION_CLOSE

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 22](https://developer.android.com/sdkExtensions)

```
public static final int RESPONSE_ACTION_CLOSE
```

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 `https://developer.android.com/reference/android/net/http/Proxy`. HttpEngine will then try the next `https://developer.android.com/reference/android/net/http/Proxy` in the list
passed to `https://developer.android.com/reference/android/net/http/ProxyOptions` (refer to that class documentation for more info).

<br />

Constant Value:

0
(0x00000000)


### RESPONSE_ACTION_PROCEED

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 22](https://developer.android.com/sdkExtensions)

```
public static final int RESPONSE_ACTION_PROCEED
```

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 `https://developer.android.com/reference/android/net/http/Proxy`. HttpEngine will then try the next `https://developer.android.com/reference/android/net/http/Proxy` in
the list passed to `https://developer.android.com/reference/android/net/http/ProxyOptions` (refer to that class documentation for more info)

<br />

Constant Value:

1
(0x00000001)


## Public methods

### onBeforeRequest

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 22](https://developer.android.com/sdkExtensions)

```
public abstract void onBeforeRequest (Proxy.HttpConnectCallback.Request request)
```

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 `https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback.Request` to learn how a request can be manipulated/canceled.

<br />

| Parameters ||
|---|---|
| `request` | `Proxy.HttpConnectCallback.Request`: Represents the HTTP CONNECT request that will be sent to the proxy. This value cannot be `null`. <br /> |

### onResponseReceived

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 22](https://developer.android.com/sdkExtensions)

```
public abstract int onResponseReceived (List<Pair<String, String>> responseHeaders, 
                int statusCode)
```

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 `https://developer.android.com/reference/java/lang/Throwable`, the fate of the tunnel will be
as if `https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback#RESPONSE_ACTION_CLOSE` had been returned. The `https://developer.android.com/reference/java/lang/Throwable`
will not be caught.

<br />

| Parameters ||
|---|---|
| `responseHeaders` | `List`: The list of headers contained in the response to the HTTP CONNECT request. This value cannot be `null`. <br /> |
| `statusCode` | `int`: The HTTP status code contained in the response to the HTTP CONNECT request. <br /> |

| Returns ||
|---|---|
| `int` | A `https://developer.android.com/` value representing what should be done with this tunnel connection. Refer to `https://developer.android.com/` documentation. Value is one of the following: - `https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback#RESPONSE_ACTION_CLOSE` - `https://developer.android.com/reference/android/net/http/Proxy.HttpConnectCallback#RESPONSE_ACTION_PROCEED` |