Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions) Summary: [Nested Classes](https://developer.android.com/reference/android/net/http/HttpEngine#nestedclasses) \| [Methods](https://developer.android.com/reference/android/net/http/HttpEngine#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/http/HttpEngine#inhmethods)

# HttpEngine

*** ** * ** ***


`
public


abstract
class
HttpEngine
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.http.HttpEngine |

<br />

*** ** * ** ***

An engine to process `https://developer.android.com/reference/android/net/http/UrlRequest`s, which uses the best HTTP stack available on the current
platform. An instance of this class can be created using `https://developer.android.com/reference/android/net/http/HttpEngine.Builder`.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/net/http/HttpEngine.Builder` A builder for `https://developer.android.com/reference/android/net/http/HttpEngine`s, which allows runtime configuration of `https://developer.android.com/reference/android/net/http/HttpEngine`. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/net/http/HttpEngine#bindToNetwork(android.net.Network)(https://developer.android.com/reference/android/net/Network network) ` Binds the engine to the specified network. |
| ` abstract https://developer.android.com/reference/java/net/URLStreamHandlerFactory` | ` https://developer.android.com/reference/android/net/http/HttpEngine#createUrlStreamHandlerFactory()() ` Creates a `https://developer.android.com/reference/java/net/URLStreamHandlerFactory` to handle HTTP and HTTPS traffic. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/net/http/HttpEngine#getVersionString()() ` |
| ` abstract https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder` | ` https://developer.android.com/reference/android/net/http/HttpEngine#newBidirectionalStreamBuilder(java.lang.String,%20java.util.concurrent.Executor,%20android.net.http.BidirectionalStream.Callback)(https://developer.android.com/reference/java/lang/String url, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback callback) ` Creates a builder for `https://developer.android.com/reference/android/net/http/BidirectionalStream` objects. |
| ` abstract https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | ` https://developer.android.com/reference/android/net/http/HttpEngine#newUrlRequestBuilder(java.lang.String,%20java.util.concurrent.Executor,%20android.net.http.UrlRequest.Callback)(https://developer.android.com/reference/java/lang/String url, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/net/http/UrlRequest.Callback callback) ` Creates a builder for `https://developer.android.com/reference/android/net/http/UrlRequest`. |
| ` abstract https://developer.android.com/reference/java/net/URLConnection` | ` https://developer.android.com/reference/android/net/http/HttpEngine#openConnection(java.net.URL)(https://developer.android.com/reference/java/net/URL url) ` Establishes a new connection to the resource specified by the `https://developer.android.com/reference/java/net/URL` `url`. |
| ` abstract void` | ` https://developer.android.com/reference/android/net/http/HttpEngine#shutdown()() ` Shuts down the `https://developer.android.com/reference/android/net/http/HttpEngine` if there are no active requests, otherwise throws an exception. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public methods

### bindToNetwork

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

```
public void bindToNetwork (Network network)
```

Binds the engine to the specified network. All requests created through this engine
will use the network associated to this handle. If this network disconnects all requests will
fail, the exact error will depend on the stage of request processing when the network
disconnects.

<br />

| Parameters ||
|---|---|
| `network` | `Network`: the network to bind the engine to. Specify `null` to unbind. <br /> |

### createUrlStreamHandlerFactory

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

```
public abstract URLStreamHandlerFactory createUrlStreamHandlerFactory ()
```

Creates a `https://developer.android.com/reference/java/net/URLStreamHandlerFactory` to handle HTTP and HTTPS
traffic. An instance of this class can be installed via
`https://developer.android.com/reference/java/net/URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)` thus using this `https://developer.android.com/reference/android/net/http/HttpEngine` by default for
all requests created via `https://developer.android.com/reference/java/net/URL#openConnection()`.


This `https://developer.android.com/reference/java/net/HttpURLConnection` implementation does not implement all features
offered by the API:

- the HTTP cache installed via `https://developer.android.com/reference/android/net/http/HttpResponseCache#install(java.io.File,%20long)`
- the HTTP authentication method installed via `https://developer.android.com/reference/java/net/Authenticator#setDefault(java.net.Authenticator)`
- the HTTP cookie storage installed via `https://developer.android.com/reference/java/net/CookieHandler#setDefault(java.net.CookieHandler)`


While we support and encourages requests using the HTTPS protocol, we don't provide support
for the `https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection` API. This lack of support also includes not using certain
HTTPS features provided via `https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection`:

- the HTTPS hostname verifier installed via `https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection#setDefaultHostnameVerifier(javax.net.ssl.HostnameVerifier)`
- the HTTPS socket factory installed via `https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection#setDefaultSSLSocketFactory(javax.net.ssl.SSLSocketFactory)`

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/net/URLStreamHandlerFactory` | an `https://developer.android.com/reference/java/net/URLStreamHandlerFactory` instance implemented by this `https://developer.android.com/reference/android/net/http/HttpEngine`. This value cannot be `null`. <br /> |

### getVersionString

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

```
public static String getVersionString ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a human-readable version string of the engine. This value cannot be `null`. <br /> |

### newBidirectionalStreamBuilder

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

```
public abstract BidirectionalStream.Builder newBidirectionalStreamBuilder (String url, 
                Executor executor, 
                BidirectionalStream.Callback callback)
```

Creates a builder for `https://developer.android.com/reference/android/net/http/BidirectionalStream` objects. All callbacks for
generated `BidirectionalStream` objects will be invoked on
`executor`. `executor` must not run tasks on the
current thread, otherwise the networking operations may block and exceptions
may be thrown at shutdown time.

<br />

| Parameters ||
|---|---|
| `url` | `String`: URL for the generated streams. This value cannot be `null`. <br /> |
| `executor` | `Executor`: the `https://developer.android.com/reference/java/util/concurrent/Executor` on which `callback` methods will be invoked. This value cannot be `null`. <br /> |
| `callback` | `BidirectionalStream.Callback`: the `https://developer.android.com/reference/android/net/http/BidirectionalStream.Callback` object that gets invoked upon different events occurring. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/BidirectionalStream.Builder` | the created builder. This value cannot be `null`. <br /> |

### newUrlRequestBuilder

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

```
public abstract UrlRequest.Builder newUrlRequestBuilder (String url, 
                Executor executor, 
                UrlRequest.Callback callback)
```

Creates a builder for `https://developer.android.com/reference/android/net/http/UrlRequest`. All callbacks for
generated `https://developer.android.com/reference/android/net/http/UrlRequest` objects will be invoked on
`executor`'s threads. `executor` must not run tasks on the
thread calling `https://developer.android.com/reference/java/util/concurrent/Executor#execute(java.lang.Runnable)` to prevent blocking networking
operations and causing exceptions during shutdown.

<br />

| Parameters ||
|---|---|
| `url` | `String`: URL for the generated requests. This value cannot be `null`. <br /> |
| `executor` | `Executor`: `https://developer.android.com/reference/java/util/concurrent/Executor` on which all callbacks will be invoked. This value cannot be `null`. <br /> |
| `callback` | `UrlRequest.Callback`: callback object that gets invoked on different events. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/UrlRequest.Builder` | This value cannot be `null`. <br /> |

### openConnection

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

```
public abstract URLConnection openConnection (URL url)
```

Establishes a new connection to the resource specified by the `https://developer.android.com/reference/java/net/URL` `url`.


**Note:** This `https://developer.android.com/reference/java/net/HttpURLConnection` implementation is subject to certain
limitations, see `https://developer.android.com/reference/android/net/http/HttpEngine#createUrlStreamHandlerFactory()` for details.

<br />

| Parameters ||
|---|---|
| `url` | `URL`: URL of resource to connect to. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/net/URLConnection` | an `https://developer.android.com/reference/java/net/HttpURLConnection` instance implemented by this `https://developer.android.com/reference/android/net/http/HttpEngine`. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an error occurs while opening the connection. |

### shutdown

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

```
public abstract void shutdown ()
```

Shuts down the `https://developer.android.com/reference/android/net/http/HttpEngine` if there are no active requests,
otherwise throws an exception.

Cannot be called on network thread - the thread the HTTP stack calls into
Executor on (which is different from the thread the Executor invokes
callbacks on). May block until all the `https://developer.android.com/reference/android/net/http/HttpEngine` resources have been cleaned up.

<br />