# UrlRequest.Builder


```
abstract class UrlRequest.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest`s. Allows configuring requests before constructing them with `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#build()`. The builder can be created by calling `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/CronetEngine#newUrlRequestBuilder(java.lang.String,org.chromium.net.UrlRequest.Callback,java.util.concurrent.Executor)`.

## Summary

| ### 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/UrlRequest.Builder#REQUEST_PRIORITY_HIGHEST() = 4` Highest request priority. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#REQUEST_PRIORITY_IDLE() = 0` Lowest request priority. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#REQUEST_PRIORITY_LOW() = 2` Low request priority. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#REQUEST_PRIORITY_LOWEST() = 1` Very low request priority. |
| `const https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#REQUEST_PRIORITY_MEDIUM() = 3` Medium request priority. |

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

| ### Public functions |
|---|---|
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#addHeader(java.lang.String,java.lang.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. |
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#addRequestAnnotation(java.lang.Object)(annotation: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!)` Associates the annotation object with this request. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#allowDirectExecutor()()` Marks that 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/java/util/concurrent/ThreadPoolExecutor.CallerRunsPolicy.html`. |
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#bindToNetwork(long)(networkHandle: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` Binds the request to the specified network handle. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#build()()` Creates a `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest` using configuration within this `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder`. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#disableCache()()` Disables cache for the request. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setHttpMethod(java.lang.String)(method: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!)` Sets the HTTP method verb to use for this request. |
| `abstract https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setPriority(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/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#REQUEST_PRIORITY_IDLE()` values. |
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `@https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Experimental https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setRawCompressionDictionary(byte[],java.nio.ByteBuffer,java.lang.String)( dictionarySha256Hash: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html!, dictionary: https://developer.android.com/reference/java/nio/ByteBuffer.html!, dictionaryId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html! )` Allows Cronet to use the specified compression dictionary for this request. |
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setRequestFinishedListener(org.chromium.net.RequestFinishedInfo.Listener)(listener: https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/RequestFinishedInfo.Listener!)` Sets a listener that gets invoked after `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Callback#onCanceled(org.chromium.net.UrlRequest,org.chromium.net.UrlResponseInfo)`, `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Callback#onFailed(org.chromium.net.UrlRequest,org.chromium.net.UrlResponseInfo,org.chromium.net.CronetException)` or `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Callback#onSucceeded(org.chromium.net.UrlRequest,org.chromium.net.UrlResponseInfo)` return. |
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setTrafficStatsTag(int)(tag: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets `https://developer.android.com/reference/android/net/TrafficStats.html` tag to use when accounting socket traffic caused by this request. |
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setTrafficStatsUid(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 https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setUploadDataProvider(org.chromium.net.UploadDataProvider,java.util.concurrent.Executor)( uploadDataProvider: https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UploadDataProvider!, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html! )` Sets upload data provider. |

## Constants

### REQUEST_PRIORITY_HIGHEST

```
const val REQUEST_PRIORITY_HIGHEST = 4: Int
```

Highest request priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setPriority(int)`.

### REQUEST_PRIORITY_IDLE

```
const val REQUEST_PRIORITY_IDLE = 0: Int
```

Lowest request priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setPriority(int)`.

### REQUEST_PRIORITY_LOW

```
const val REQUEST_PRIORITY_LOW = 2: Int
```

Low request priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setPriority(int)`.

### REQUEST_PRIORITY_LOWEST

```
const val REQUEST_PRIORITY_LOWEST = 1: Int
```

Very low request priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setPriority(int)`.

### REQUEST_PRIORITY_MEDIUM

```
const val REQUEST_PRIORITY_MEDIUM = 3: Int
```

Medium request priority. Passed to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#setPriority(int)`. This is the default priority given to the request.

## Public constructors

### Builder

```
Builder()
```

## Public functions

### addHeader

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

Adds a request header.

| Parameters |
|---|---|
| `header: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | header name. |
| `value: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | header value. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### addRequestAnnotation

```
fun addRequestAnnotation(annotation: Any!): UrlRequest.Builder!
```

Associates the annotation object with this request. May add more than one. Passed through to a `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/RequestFinishedInfo.Listener`, see `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/RequestFinishedInfo#getAnnotations()`.

| Parameters |
|---|---|
| `annotation: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!` | an object to pass on to the `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/RequestFinishedInfo.Listener` with a `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/RequestFinishedInfo`. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### allowDirectExecutor

```
abstract fun allowDirectExecutor(): UrlRequest.Builder!
```

Marks that 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/java/util/concurrent/ThreadPoolExecutor.CallerRunsPolicy.html`.

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

### bindToNetwork

```
fun bindToNetwork(networkHandle: Long): UrlRequest.Builder!
```

Binds the request to the specified network handle. Cronet 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. Network handles can be obtained through `Network#getNetworkHandle`. Only available starting from Android Marshmallow.

| Parameters |
|---|---|
| `networkHandle: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html` | the network handle to bind the request to. Specify `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/CronetEngine#UNBIND_NETWORK_HANDLE()` to unbind. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### build

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

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

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest!` | constructed `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest` using configuration within this `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder`. |

### disableCache

```
abstract fun disableCache(): UrlRequest.Builder!
```

Disables cache for the request. If context is not set up to use cache, this call has no effect.

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### setHttpMethod

```
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: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | "GET", "HEAD", "DELETE", "POST" or "PUT". |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### setPriority

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

Sets priority of the request which should be one of the `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#REQUEST_PRIORITY_IDLE()` values. The request is given `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#REQUEST_PRIORITY_MEDIUM()` priority if this method is not called.

| Parameters |
|---|---|
| `priority: 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/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder#REQUEST_PRIORITY_IDLE()` values. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### setRawCompressionDictionary

```
@UrlRequest.Experimental
fun setRawCompressionDictionary(
    dictionarySha256Hash: ByteArray!,
    dictionary: ByteBuffer!,
    dictionaryId: String!
): UrlRequest.Builder!
```

Allows Cronet to use the specified compression dictionary for this request. When specified, Cronet might signal to the server the availability of said compression dictionary. For this to have any effect, the CronetEngine that will execute this request must have been configured to enable a compression scheme that supports external dictionaries. This partially implements draft-ietf-httpbis-compression-dictionary within Cronet. Cronet won't directly handle "Use-As-Dictionary" response headers, it will instead rely on the embedder to: either, handle them and later call UrlRequest.Builder#setCompressionDictionary for requests which match Use-As-Dictionary's rules; or, fetch compression dictionaries via some other out of band mechanism, and later call UrlRequest.Builder#setCompressionDictionary. Cronet will interpret the dictionary as matching only this UrlRequest. If said request is redirected, and the embedder decides to follow the redirect, the dictionary will match also the new URL.

| Parameters |
|---|---|
| `dictionarySha256Hash: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html!` | the SHA-256 of the specified compression dictionary. |
| `dictionary: https://developer.android.com/reference/java/nio/ByteBuffer.html!` | the compression dictionary that Cronet can use for this UrlRequest. This must be a direct ByteBuffer. |
| `dictionaryId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | the optional ID associated with this dictionary, must be an empty string if missing. If present, this will be sent via the Dictionary-ID header. You would need to specify this if the server specified an id in its "Use-As-Dictionary" response. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### setRequestFinishedListener

```
fun setRequestFinishedListener(listener: RequestFinishedInfo.Listener!): UrlRequest.Builder!
```

Sets a listener that gets invoked after `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Callback#onCanceled(org.chromium.net.UrlRequest,org.chromium.net.UrlResponseInfo)`, `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Callback#onFailed(org.chromium.net.UrlRequest,org.chromium.net.UrlResponseInfo,org.chromium.net.CronetException)` or `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Callback#onSucceeded(org.chromium.net.UrlRequest,org.chromium.net.UrlResponseInfo)` return.

The listener is invoked with the request finished info on an `https://developer.android.com/reference/java/util/concurrent/Executor.html` provided by `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/RequestFinishedInfo.Listener#getExecutor()`.

| Parameters |
|---|---|
| `listener: https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/RequestFinishedInfo.Listener!` | the listener for finished requests. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### setTrafficStatsTag

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

Sets `https://developer.android.com/reference/android/net/TrafficStats.html` tag to use when accounting socket traffic caused by this request. See `https://developer.android.com/reference/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: 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/android/app/DownloadManager.html` when performing traffic on behalf of an application. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### setTrafficStatsUid

```
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/android/net/TrafficStats.html` for more information. Designed for use when performing an operation on behalf of another application. Caller must hold `
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: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | the UID to attribute socket traffic caused by this request. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |

### setUploadDataProvider

```
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: https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UploadDataProvider!` | responsible for providing the upload data. |
| `executor: https://developer.android.com/reference/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. |

| Returns |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/UrlRequest.Builder!` | the builder to facilitate chaining. |