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

# Builder

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/net/http/UrlRequest.Builder "View this page in Java")

```
abstract class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.net.http.UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) |

Builder for `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest`s. Allows configuring requests before constructing them with `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#build()`. The builder can be created by calling `https://developer.android.com/reference/kotlin/android/net/http/HttpEngine#newUrlRequestBuilder(kotlin.String,%20java.util.concurrent.Executor,%20android.net.http.UrlRequest.Callback)`.

## Summary

| Public methods ||
|---|---|
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#addHeader(kotlin.String,%20kotlin.String)(header: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, value: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Adds a request header. |
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#bindToNetwork(android.net.Network)(network: https://developer.android.com/reference/kotlin/android/net/Network.html#?)` Binds the request to the specified network. |
| abstract [UrlRequest](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#build()()` Creates a `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest` using configuration within this `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#`. |
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#setCacheDisabled(kotlin.Boolean)(disableCache: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` WARNING: This method should not be called with \`setCacheDisabled(false)\` as this may lead to incorrect behaviour on older versions of HttpEngine. |
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#setDirectExecutorAllowed(kotlin.Boolean)(allowDirectExecutor: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` WARNING: This method should not be called with \`setDirectExecutorAllowed(false)\` as this may lead to incorrect behaviour on older versions of HttpEngine. |
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#setHttpMethod(kotlin.String)(method: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Sets the HTTP method verb to use for this request. |
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#setPriority(kotlin.Int)(priority: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets priority of the request which should be one of the `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest#REQUEST_PRIORITY_IDLE:kotlin.Int` values. |
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#setTrafficStatsTag(kotlin.Int)(tag: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets `https://developer.android.com/reference/kotlin/android/net/TrafficStats.html#` tag to use when accounting socket traffic caused by this request. |
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#setTrafficStatsUid(kotlin.Int)(uid: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets specific UID to use when accounting socket traffic caused by this request. |
| abstract [UrlRequest.Builder](https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#) | `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#setUploadDataProvider(android.net.http.UploadDataProvider,%20java.util.concurrent.Executor)(uploadDataProvider: https://developer.android.com/reference/kotlin/android/net/http/UploadDataProvider, executor: https://developer.android.com/reference/kotlin/java/util/concurrent/Executor.html#)` Sets upload data provider. |

## Public methods

### addHeader

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

```
abstract fun addHeader(
    header: String, 
    value: String
): UrlRequest.Builder
```

Adds a request header.

| Parameters ||
|---|---|
| `header` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html): header name. This value cannot be `null`. |
| `value` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html): header value. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |

### bindToNetwork

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

```
abstract fun bindToNetwork(network: Network?): UrlRequest.Builder
```

Binds the request to the specified network. The HTTP stack will send this request only using the network associated to this handle. If this network disconnects the request will fail, the exact error will depend on the stage of request processing when the network disconnects.

| Parameters ||
|---|---|
| `network` | [Network](https://developer.android.com/reference/kotlin/android/net/Network.html#)?: the network to bind the request to. Specify `null` to unbind. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |

### build

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

```
abstract fun build(): UrlRequest
```

Creates a `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest` using configuration within this `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#`. The returned `UrlRequest` can then be started by calling `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest#start()`.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest` | constructed `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest` using configuration within this `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#`. This value cannot be `null`. |

### setCacheDisabled

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

```
abstract fun setCacheDisabled(disableCache: Boolean): UrlRequest.Builder
```

WARNING: This method should not be called with \`setCacheDisabled(false)\` as this may lead to incorrect behaviour on older versions of HttpEngine. Whether to disable cache for the request. If the engine is not set up to use cache, this call has no effect.

| Parameters ||
|---|---|
| `disableCache` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): `true` to disable cache, `false` otherwise. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |

### setDirectExecutorAllowed

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

```
abstract fun setDirectExecutorAllowed(allowDirectExecutor: Boolean): UrlRequest.Builder
```

WARNING: This method should not be called with \`setDirectExecutorAllowed(false)\` as this may lead to incorrect behaviour on older versions of HttpEngine. Marks whether the executors this request will use to notify callbacks (for `UploadDataProvider`s and `UrlRequest.Callback`s) is intentionally performing inline execution, like Guava's directExecutor or `https://developer.android.com/reference/kotlin/java/util/concurrent/ThreadPoolExecutor.CallerRunsPolicy.html#`.

**Warning:** If set to true: This option makes it easy to accidentally block the network thread. This should not be done if your callbacks perform disk I/O, acquire locks, or call into other code you don't carefully control and audit.

| Parameters ||
|---|---|
| `allowDirectExecutor` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): `true` to allow executors performing inline execution, `false` otherwise. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |

### setHttpMethod

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

```
abstract fun setHttpMethod(method: String): UrlRequest.Builder
```

Sets the HTTP method verb to use for this request.

The default when this method is not called is "GET" if the request has no body or "POST" if it does.

| Parameters ||
|---|---|
| `method` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html): "GET", "HEAD", "DELETE", "POST" or "PUT". This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |

### setPriority

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

```
abstract fun setPriority(priority: Int): UrlRequest.Builder
```

Sets priority of the request which should be one of the `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest#REQUEST_PRIORITY_IDLE:kotlin.Int` values. The request is given `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest#REQUEST_PRIORITY_MEDIUM:kotlin.Int` priority if this method is not called.

| Parameters ||
|---|---|
| `priority` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): priority of the request which should be one of the `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest#REQUEST_PRIORITY_IDLE:kotlin.Int` values. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |

### setTrafficStatsTag

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

```
abstract fun setTrafficStatsTag(tag: Int): UrlRequest.Builder
```

Sets `https://developer.android.com/reference/kotlin/android/net/TrafficStats.html#` tag to use when accounting socket traffic caused by this request. See `https://developer.android.com/reference/kotlin/android/net/TrafficStats.html#` for more information. If no tag is set (e.g. this method isn't called), then Android accounts for the socket traffic caused by this request as if the tag value were set to 0.

**NOTE:**Setting a tag disallows sharing of sockets with requests with other tags, which may adversely effect performance by prohibiting connection sharing. In other words use of multiplexed sockets (e.g. HTTP/2 and QUIC) will only be allowed if all requests have the same socket tag.

| Parameters ||
|---|---|
| `tag` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the tag value used to when accounting for socket traffic caused by this request. Tags between 0xFFFFFF00 and 0xFFFFFFFF are reserved and used internally by system services like `https://developer.android.com/reference/kotlin/android/app/DownloadManager.html#` when performing traffic on behalf of an application. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |

### setTrafficStatsUid

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

```
abstract fun setTrafficStatsUid(uid: Int): UrlRequest.Builder
```

Sets specific UID to use when accounting socket traffic caused by this request. See `https://developer.android.com/reference/kotlin/android/net/TrafficStats.html#` for more information. Designed for use when performing an operation on behalf of another application. Caller must hold `android.Manifest.permission#MODIFY_NETWORK_ACCOUNTING` permission. By default traffic is attributed to UID of caller.

**NOTE:**Setting a UID disallows sharing of sockets with requests with other UIDs, which may adversely effect performance by prohibiting connection sharing. In other words use of multiplexed sockets (e.g. HTTP/2 and QUIC) will only be allowed if all requests have the same UID set.

| Parameters ||
|---|---|
| `uid` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the UID to attribute socket traffic caused by this request. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |

### setUploadDataProvider

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

```
abstract fun setUploadDataProvider(
    uploadDataProvider: UploadDataProvider, 
    executor: Executor
): UrlRequest.Builder
```

Sets upload data provider. Switches method to "POST" if not explicitly set. Starting the request will throw an exception if a Content-Type header is not set.

| Parameters ||
|---|---|
| `uploadDataProvider` | [UploadDataProvider](https://developer.android.com/reference/kotlin/android/net/http/UploadDataProvider): responsible for providing the upload data. This value cannot be `null`. |
| `executor` | [Executor](https://developer.android.com/reference/kotlin/java/util/concurrent/Executor.html#): All `uploadDataProvider` methods will be invoked using this `Executor`. May optionally be the same `Executor` the request itself is using. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/net/http/UrlRequest.Builder#` | the builder to facilitate chaining. This value cannot be `null`. |