BidirectionalStream.Builder

abstract class BidirectionalStream.Builder


Builder for BidirectionalStreams. Allows configuring stream before constructing it via build. Created by newBidirectionalStreamBuilder.

Summary

Constants

const Int

Highest stream priority.

const Int

Lowest stream priority.

const Int

Low stream priority.

const Int

Very low stream priority.

const Int

Medium stream priority.

Public constructors

Public functions

abstract BidirectionalStream.Builder!
addHeader(header: String!, value: String!)

Adds a request header.

BidirectionalStream.Builder!
addRequestAnnotation(annotation: Any!)

Associates the annotation object with this request.

BidirectionalStream.Builder!
bindToNetwork(networkHandle: Long)

Binds the request to the specified network handle.

abstract BidirectionalStream!

Creates a BidirectionalStream using configuration from this Builder.

abstract BidirectionalStream.Builder!
delayRequestHeadersUntilFirstFlush(
    delayRequestHeadersUntilFirstFlush: Boolean
)

Delays sending request headers until flush is called.

abstract BidirectionalStream.Builder!

Sets the HTTP method for the request.

abstract BidirectionalStream.Builder!
setPriority(priority: Int)

Sets priority of the stream which should be one of the STREAM_PRIORITY_* values.

BidirectionalStream.Builder!

Sets android.net.TrafficStats tag to use when accounting socket traffic caused by this request.

BidirectionalStream.Builder!

Sets specific UID to use when accounting socket traffic caused by this request.

Constants

STREAM_PRIORITY_HIGHEST

const val STREAM_PRIORITY_HIGHEST = 4: Int

Highest stream priority. Passed to setPriority.

STREAM_PRIORITY_IDLE

const val STREAM_PRIORITY_IDLE = 0: Int

Lowest stream priority. Passed to setPriority.

STREAM_PRIORITY_LOW

const val STREAM_PRIORITY_LOW = 2: Int

Low stream priority. Passed to setPriority.

STREAM_PRIORITY_LOWEST

const val STREAM_PRIORITY_LOWEST = 1: Int

Very low stream priority. Passed to setPriority.

STREAM_PRIORITY_MEDIUM

const val STREAM_PRIORITY_MEDIUM = 3: Int

Medium stream priority. Passed to setPriority. This is the default priority given to the stream.

Public constructors

Builder

Builder()

Public functions

addHeader

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

Adds a request header. Returns builder to facilitate chaining.

Parameters
header: String!

the header name

value: String!

the header value

Returns
BidirectionalStream.Builder!

the builder to facilitate chaining

addRequestAnnotation

fun addRequestAnnotation(annotation: Any!): BidirectionalStream.Builder!

Associates the annotation object with this request. May add more than one. Passed through to a RequestFinishedInfo.Listener, see getAnnotations.

Parameters
annotation: Any!

an object to pass on to the RequestFinishedInfo.Listener with a RequestFinishedInfo.

Returns
BidirectionalStream.Builder!

the builder to facilitate chaining.

bindToNetwork

fun bindToNetwork(networkHandle: Long): BidirectionalStream.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: Long

the network handle to bind the request to. Specify UNBIND_NETWORK_HANDLE to unbind.

Returns
BidirectionalStream.Builder!

the builder to facilitate chaining.

build

abstract fun build(): BidirectionalStream!

Creates a BidirectionalStream using configuration from this Builder. The returned BidirectionalStream can then be started by calling start.

Returns
BidirectionalStream!

constructed BidirectionalStream using configuration from this Builder

delayRequestHeadersUntilFirstFlush

abstract fun delayRequestHeadersUntilFirstFlush(
    delayRequestHeadersUntilFirstFlush: Boolean
): BidirectionalStream.Builder!

Delays sending request headers until 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

if true, sending request headers will be delayed until flush() is called.

Returns
BidirectionalStream.Builder!

the builder to facilitate chaining.

setHttpMethod

abstract fun setHttpMethod(method: String!): BidirectionalStream.Builder!

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

Parameters
method: String!

the method to use for request. Default is 'POST'

Returns
BidirectionalStream.Builder!

the builder to facilitate chaining

setPriority

abstract fun setPriority(priority: Int): BidirectionalStream.Builder!

Sets priority of the stream which should be one of the STREAM_PRIORITY_* values. The stream is given STREAM_PRIORITY_MEDIUM priority if this method is not called.

Parameters
priority: Int

priority of the stream which should be one of the STREAM_PRIORITY_* values.

Returns
BidirectionalStream.Builder!

the builder to facilitate chaining.

setTrafficStatsTag

fun setTrafficStatsTag(tag: Int): BidirectionalStream.Builder!

Sets android.net.TrafficStats tag to use when accounting socket traffic caused by this request. See android.net.TrafficStats 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

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 when performing traffic on behalf of an application.

Returns
BidirectionalStream.Builder!

the builder to facilitate chaining.

setTrafficStatsUid

fun setTrafficStatsUid(uid: Int): BidirectionalStream.Builder!

Sets specific UID to use when accounting socket traffic caused by this request. See android.net.TrafficStats 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: Int

the UID to attribute socket traffic caused by this request.

Returns
BidirectionalStream.Builder!

the builder to facilitate chaining.