# HttpEngineDataSource.Factory

Artifact: [androidx.media3:media3-datasource](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/datasource/HttpEngineDataSource.java+class:androidx.media3.datasource.HttpEngineDataSource.Factory)

*** ** * ** ***


```
class HttpEngineDataSource.Factory : HttpDataSource.Factory
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory` for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource` instances.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#Factory(android.net.http.HttpEngine,java.util.concurrent.Executor)(httpEngine: https://developer.android.com/reference/android/net/http/HttpEngine.html!, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html!)` Creates an instance. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource!` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#createDataSource()()` Creates a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instance. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setConnectionTimeoutMs(int)(connectTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the connect timeout, in milliseconds. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setContentTypePredicate(com.google.common.base.Predicate<java.lang.String>)(contentTypePredicate: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>?)` Sets a content type `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setDefaultRequestProperties(java.util.Map<java.lang.String,java.lang.String>)( defaultRequestProperties: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>! )` Sets the default request headers for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource` instances created by the factory. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setHandleSetCookieRequests(boolean)(handleSetCookieRequests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setKeepPostFor302Redirects(boolean)(keepPostFor302Redirects: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setReadTimeoutMs(int)(readTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the read timeout, in milliseconds. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setRequestPriority(int)(requestPriority: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the priority of requests made by `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource` instances created by this factory. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setResetTimeoutOnRedirects(boolean)(resetTimeoutOnRedirects: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether the connect timeout is reset when a redirect occurs. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setTransferListener(androidx.media3.datasource.TransferListener)(transferListener: https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener?)` Sets the `https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener` that will be used. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory#setUserAgent(java.lang.String)(userAgent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Sets the user agent that will be used. |

### Inherited functions

From [androidx.media3.datasource.DataSource.Factory](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory) `abstract https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi
https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource.Factory#createDataSource()()`

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instance.

## Public constructors

### Factory

```
Factory(httpEngine: HttpEngine!, executor: Executor!)
```

Creates an instance.

| Parameters |
|---|---|
| `httpEngine: https://developer.android.com/reference/android/net/http/HttpEngine.html!` | An `https://developer.android.com/reference/android/net/http/HttpEngine.html` to make the requests. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html!` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` that will handle responses. This may be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread hop from HttpEngine's internal network thread to the response handling thread. However, to avoid slowing down overall network performance, care must be taken to make sure response handling is a fast operation when using a direct executor. |

## Public functions

### createDataSource

```
@UnstableApi
fun createDataSource(): HttpDataSource!
```

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource` instance.

### setConnectionTimeoutMs

```
@CanIgnoreReturnValue
@UnstableApi
fun setConnectionTimeoutMs(connectTimeoutMs: Int): HttpEngineDataSource.Factory!
```

Sets the connect timeout, in milliseconds.

The default is `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS()`.

| Parameters |
|---|---|
| `connectTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The connect timeout, in milliseconds, that will be used. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |

### setContentTypePredicate

```
@CanIgnoreReturnValue
@UnstableApi
fun setContentTypePredicate(contentTypePredicate: Predicate<String!>?): HttpEngineDataSource.Factory!
```

Sets a content type `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html`. If a content type is rejected by the predicate then a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.InvalidContentTypeException` is thrown from `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource#open(androidx.media3.datasource.DataSpec)`.

The default is `null`.

| Parameters |
|---|---|
| `contentTypePredicate: https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>?` | The content type `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Predicate.html`, or `null` to clear a predicate that was previously set. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |

### setDefaultRequestProperties

```
@CanIgnoreReturnValue
@UnstableApi
fun setDefaultRequestProperties(
    defaultRequestProperties: (Mutable)Map<String!, String!>!
): HttpEngineDataSource.Factory!
```

Sets the default request headers for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource` instances created by the factory.

The new request properties will be used for future requests made by `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource` created by the factory, including instances that have already been created. Modifying the `defaultRequestProperties` map after a call to this method will have no effect, and so it's necessary to call this method again each time the request properties need to be updated.

| Parameters |
|---|---|
| `defaultRequestProperties: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | The default request properties. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |

### setHandleSetCookieRequests

```
@CanIgnoreReturnValue
@UnstableApi
fun setHandleSetCookieRequests(handleSetCookieRequests: Boolean): HttpEngineDataSource.Factory!
```

Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.

The default is `false`.

| Parameters |
|---|---|
| `handleSetCookieRequests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |

### setKeepPostFor302Redirects

```
@CanIgnoreReturnValue
@UnstableApi
fun setKeepPostFor302Redirects(keepPostFor302Redirects: Boolean): HttpEngineDataSource.Factory!
```

Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.

### setReadTimeoutMs

```
@CanIgnoreReturnValue
@UnstableApi
fun setReadTimeoutMs(readTimeoutMs: Int): HttpEngineDataSource.Factory!
```

Sets the read timeout, in milliseconds.

The default is `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource#DEFAULT_READ_TIMEOUT_MILLIS()`.

| Parameters |
|---|---|
| `readTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The connect timeout, in milliseconds, that will be used. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |

### setRequestPriority

```
@CanIgnoreReturnValue
@UnstableApi
fun setRequestPriority(requestPriority: Int): HttpEngineDataSource.Factory!
```

Sets the priority of requests made by `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource` instances created by this factory.

The default is `https://developer.android.com/reference/android/net/http/UrlRequest.html#REQUEST_PRIORITY_MEDIUM`.

| Parameters |
|---|---|
| `requestPriority: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The request priority, which should be one of HttpEngine's ` UrlRequest#REQUEST_PRIORITY_*` constants. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |

### setResetTimeoutOnRedirects

```
@CanIgnoreReturnValue
@UnstableApi
fun setResetTimeoutOnRedirects(resetTimeoutOnRedirects: Boolean): HttpEngineDataSource.Factory!
```

Sets whether the connect timeout is reset when a redirect occurs.

The default is `false`.

| Parameters |
|---|---|
| `resetTimeoutOnRedirects: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the connect timeout is reset when a redirect occurs. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |

### setTransferListener

```
@CanIgnoreReturnValue
@UnstableApi
fun setTransferListener(transferListener: TransferListener?): HttpEngineDataSource.Factory!
```

Sets the `https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener` that will be used.

The default is `null`.

See `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#addTransferListener(androidx.media3.datasource.TransferListener)`.

| Parameters |
|---|---|
| `transferListener: https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener?` | The listener that will be used. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |

### setUserAgent

```
@CanIgnoreReturnValue
fun setUserAgent(userAgent: String?): HttpEngineDataSource.Factory!
```

Sets the user agent that will be used.

The default is `null`, which causes the default user agent of the underlying `https://developer.android.com/reference/android/net/http/HttpEngine.html` to be used.

| Parameters |
|---|---|
| `userAgent: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The user agent that will be used, or `null` to use the default user agent of the underlying `https://developer.android.com/reference/android/net/http/HttpEngine.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.Factory!` | This factory. |