# BidirectionalStream.Builder

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/BidirectionalStream.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.BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#) |

Builder for[BidirectionalStream](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream)s. Allows configuring stream before constructing it via[Builder.build](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#build()).

## Summary

|                                                      Public constructors                                                       ||
|-----------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#Builder())`()` <br /> |

|                                                                                                                                                                                                                                                                                                                           Public methods                                                                                                                                                                                                                                                                                                                            ||
|-------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#) | [addHeader](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#addHeader(kotlin.String,%20kotlin.String))`(`header:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `value:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Adds a request header.                                                                                                                                                         |
| abstract[BidirectionalStream](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream)                  | [build](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#build())`()` Creates a[BidirectionalStream](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream)using configuration from this[Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#).                                                                                                                                                      |
| abstract[BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#) | [setDelayRequestHeadersUntilFirstFlushEnabled](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#setDelayRequestHeadersUntilFirstFlushEnabled(kotlin.Boolean))`(`delayRequestHeadersUntilFirstFlush:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Sets whether to delay sending request headers until[BidirectionalStream.flush()](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#flush())is called. |
| abstract[BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#) | [setHttpMethod](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#setHttpMethod(kotlin.String))`(`method:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Sets the HTTP method for the request.                                                                                                                                                                                                                                                |
| abstract[BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#) | [setPriority](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#setPriority(kotlin.Int))`(`priority:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets priority of the stream which should be one of the[STREAM_PRIORITY_*](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_PRIORITY_IDLE:kotlin.Int)values.                                                                                           |
| abstract[BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#) | [setTrafficStatsTag](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#setTrafficStatsTag(kotlin.Int))`(`tag:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets[android.net.TrafficStats](https://developer.android.com/reference/kotlin/android/net/TrafficStats.html#)tag to use when accounting socket traffic caused by this request.                                                                                                         |
| abstract[BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#) | [setTrafficStatsUid](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#setTrafficStatsUid(kotlin.Int))`(`uid:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets specific UID to use when accounting socket traffic caused by this request.                                                                                                                                                                                                        |

## Public constructors

### Builder

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()
```

## 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
): BidirectionalStream.Builder
```

Adds a request header. Returns builder to facilitate chaining.

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

|                                                                                           Return                                                                                            ||
|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| [BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.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(): BidirectionalStream
```

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

|                                                                                                                                                                                              Return                                                                                                                                                                                              ||
|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [BidirectionalStream](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream) | constructed[BidirectionalStream](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream)using configuration from this[Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#)This value cannot be`null`. |

### setDelayRequestHeadersUntilFirstFlushEnabled

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 setDelayRequestHeadersUntilFirstFlushEnabled(delayRequestHeadersUntilFirstFlush: Boolean): BidirectionalStream.Builder
```

Sets whether to delay sending request headers until[BidirectionalStream.flush()](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#flush())is called. This flag is currently only respected when QUIC is negotiated. When true, QUIC will send request header frame along with data frame(s) as a single packet when possible.

|                                                                                             Parameters                                                                                             ||
|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `delayRequestHeadersUntilFirstFlush` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):if true, sending request headers will be delayed until flush() is called. |

|                                                                                            Return                                                                                            ||
|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.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): BidirectionalStream.Builder
```

Sets the HTTP method for the request. Returns builder to facilitate chaining.

|                                                                               Parameters                                                                                ||
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `method` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the method to use for request. Default is 'POST' This value cannot be`null`. |

|                                                                                           Return                                                                                            ||
|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| [BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.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): BidirectionalStream.Builder
```

Sets priority of the stream which should be one of the[STREAM_PRIORITY_*](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_PRIORITY_IDLE:kotlin.Int)values. The stream is given[STREAM_PRIORITY_MEDIUM](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_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 stream which should be one of the[STREAM_PRIORITY_*](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_PRIORITY_IDLE:kotlin.Int)values. Value is[android.net.http.BidirectionalStream#STREAM_PRIORITY_IDLE](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_PRIORITY_IDLE:kotlin.Int),[android.net.http.BidirectionalStream#STREAM_PRIORITY_LOWEST](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_PRIORITY_LOWEST:kotlin.Int),[android.net.http.BidirectionalStream#STREAM_PRIORITY_LOW](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_PRIORITY_LOW:kotlin.Int),[android.net.http.BidirectionalStream#STREAM_PRIORITY_MEDIUM](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_PRIORITY_MEDIUM:kotlin.Int), or[android.net.http.BidirectionalStream#STREAM_PRIORITY_HIGHEST](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream#STREAM_PRIORITY_HIGHEST:kotlin.Int) |

|                                                                                            Return                                                                                            ||
|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.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): BidirectionalStream.Builder
```

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

|                                                                                            Return                                                                                            ||
|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.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): BidirectionalStream.Builder
```

Sets specific UID to use when accounting socket traffic caused by this request. See[android.net.TrafficStats](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                                                                                            ||
|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [BidirectionalStream.Builder](https://developer.android.com/reference/kotlin/android/net/http/BidirectionalStream.Builder#) | the builder to facilitate chaining. This value cannot be`null`. |