# Proxy.HttpConnectCallback


```
abstract class Proxy.HttpConnectCallback
```

<br />

*** ** * ** ***

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

Methods within this class are invoked only when both of the following are true:

```kotlin
- HttpEngine must establish a connection to the destination of an HTTP request
- The destination of the HTTP request has an https URI scheme
```
Refer to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy#createHttpProxy(int,java.lang.String,int,java.util.concurrent.Executor,org.chromium.net.Proxy.HttpConnectCallback)`'s documentation to understand how CronetEngine decides whether to establish a tunnel through an HTTP proxy.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/androidx/annotation/IntDef.html(value = ) annotation https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback.OnResponseReceivedAction` Actions that can be performed in response to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback#onResponseReceived(java.util.List<android.util.Pair<java.lang.String,java.lang.String>>,int)` being called. |
| `abstract class https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback.Request : https://developer.android.com/reference/java/lang/AutoCloseable.html` Represents an HTTP CONNECT request being sent to the proxy server. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback#RESPONSE_ACTION_CLOSE() = 0` Closes the tunnel connection, preventing it from being used to send HTTP requests. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback#RESPONSE_ACTION_PROCEED() = 1` Proceeds establishing a tunnel. |

| ### Public constructors |
|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback#HttpConnectCallback()()` |

| ### Public functions |
|---|---|
| `abstract https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback#onBeforeRequest(org.chromium.net.Proxy.HttpConnectCallback.Request)(request: https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback.Request)` Called before sending an HTTP CONNECT request to the proxy to establish a tunnel. |
| `abstract https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `@https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback.OnResponseReceivedAction https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback#onResponseReceived(java.util.List<android.util.Pair<java.lang.String,java.lang.String>>,int)( responseHeaders: (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/util/Pair.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!>!>, statusCode: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html )` Called after receiving a response to the HTTP CONNECT request sent to the proxy to establish a tunnel. |

## Constants

### RESPONSE_ACTION_CLOSE

```
const val RESPONSE_ACTION_CLOSE = 0: Int
```

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

When a tunnel connection is closed, CronetEngine will interpret it as a failure to use the associated `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy`. CronetEngine will then try the next `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy` in the list passed to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/ProxyOptions` (refer to that class documentation for more info).

### RESPONSE_ACTION_PROCEED

```
const val RESPONSE_ACTION_PROCEED = 1: Int
```

Proceeds establishing a tunnel.

This does not guarantee that the tunnel will successfully be established and used to send HTTP requests: CronetEngine will perform additional checks prior to that. Depending on their outcome, CronetEngine might still decide to close the tunnel connection. If the tunnel connection ends up being closed by CronetEngine, it will be considered as a failure to use the associated `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy`. CronetEngine will then try the next `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy` in the list passed to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/ProxyOptions` (refer to that class documentation for more info)

## Public constructors

### HttpConnectCallback

```
HttpConnectCallback()
```

## Public functions

### 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 `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback.Request` to learn how a request can be manipulated/canceled.

| Parameters |
|---|---|
| `request: https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback.Request` | Represents the HTTP CONNECT request that will be sent to the proxy. |

### onResponseReceived

```
@Proxy.HttpConnectCallback.OnResponseReceivedAction
abstract fun onResponseReceived(
    responseHeaders: (Mutable)List<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.

When sending HTTP requests to a destination with an https URI schene, CronetEngine will never use a proxy whose `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback#onResponseReceived(java.util.List<android.util.Pair<java.lang.String,java.lang.String>>,int)` callback has not been invoked.

This 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.html`, the fate of the tunnel will be as if RESPONSE_ACTION_CLOSE had been returned (the `https://developer.android.com/reference/java/lang/Throwable.html` will not be caught).

| Parameters |
|---|---|
| `responseHeaders: (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/util/Pair.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!>!>` | The list of headers contained in the response to the HTTP CONNECT request. |
| `statusCode: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | The HTTP status code contained in the response to the HTTP CONNECT request. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | A `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback.OnResponseReceivedAction` value representing what should be done with this tunnel connection. Refer to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/Proxy.HttpConnectCallback.OnResponseReceivedAction` documentation. |