Builder
abstract class Builder
kotlin.Any | |
↳ | android.net.http.UrlRequest.Builder |
Builder for UrlRequest
s. Allows configuring requests before constructing them with Builder.build
. The builder can be created by calling HttpEngine.newUrlRequestBuilder
.
Summary
Public methods | |
---|---|
abstract UrlRequest.Builder |
Adds a request header. |
abstract UrlRequest.Builder |
bindToNetwork(network: Network?) Binds the request to the specified network. |
abstract UrlRequest |
build() Creates a |
abstract UrlRequest.Builder |
setCacheDisabled(disableCache: Boolean) 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 |
setDirectExecutorAllowed(allowDirectExecutor: Boolean) 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 |
setHttpMethod(method: String) Sets the HTTP method verb to use for this request. |
abstract UrlRequest.Builder |
setPriority(priority: Int) Sets priority of the request which should be one of the |
abstract UrlRequest.Builder |
setTrafficStatsTag(tag: Int) Sets |
abstract UrlRequest.Builder |
setTrafficStatsUid(uid: Int) Sets specific UID to use when accounting socket traffic caused by this request. |
abstract UrlRequest.Builder |
setUploadDataProvider(uploadDataProvider: UploadDataProvider, executor: Executor) Sets upload data provider. |
Public methods
addHeader
abstract fun addHeader(
header: String,
value: String
): UrlRequest.Builder
Adds a request header.
Parameters | |
---|---|
header |
String: header name. This value cannot be null . |
value |
String: header value. This value cannot be null . |
Return | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |
bindToNetwork
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?: the network to bind the request to. Specify null to unbind. |
Return | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |
build
abstract fun build(): UrlRequest
Creates a UrlRequest
using configuration within this Builder
. The returned UrlRequest
can then be started by calling UrlRequest.start
.
Return | |
---|---|
UrlRequest |
constructed UrlRequest using configuration within this Builder . This value cannot be null . |
setCacheDisabled
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: true to disable cache, false otherwise. |
Return | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |
setDirectExecutorAllowed
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 java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy
.
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: true to allow executors performing inline execution, false otherwise. |
Return | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |
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 |
String: "GET", "HEAD", "DELETE", "POST" or "PUT". This value cannot be null . |
Return | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |
setPriority
abstract fun setPriority(priority: Int): UrlRequest.Builder
Sets priority of the request which should be one of the REQUEST_PRIORITY_*
values. The request is given REQUEST_PRIORITY_MEDIUM
priority if this method is not called.
Parameters | |
---|---|
priority |
Int: priority of the request which should be one of the REQUEST_PRIORITY_* values. |
Return | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |
setTrafficStatsTag
abstract fun setTrafficStatsTag(tag: Int): UrlRequest.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. |
Return | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |
setTrafficStatsUid
abstract fun setTrafficStatsUid(uid: Int): UrlRequest.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 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: the UID to attribute socket traffic caused by this request. |
Return | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |
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 |
UploadDataProvider: responsible for providing the upload data. This value cannot be null . |
executor |
Executor: 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 | |
---|---|
UrlRequest.Builder |
the builder to facilitate chaining. This value cannot be null . |