public static abstract class

UrlRequest.Builder

extends Object
java.lang.Object
   ↳ org.chromium.net.UrlRequest.Builder

Class Overview

Builder for UrlRequests. Allows configuring requests before constructing them with build(). The builder can be created by calling newUrlRequestBuilder(String, UrlRequest.Callback, Executor).

Summary

Constants
int REQUEST_PRIORITY_HIGHEST Highest request priority.
int REQUEST_PRIORITY_IDLE Lowest request priority.
int REQUEST_PRIORITY_LOW Low request priority.
int REQUEST_PRIORITY_LOWEST Very low request priority.
int REQUEST_PRIORITY_MEDIUM Medium request priority.
Public Constructors
UrlRequest.Builder()
Public Methods
abstract UrlRequest.Builder addHeader(String header, String value)
Adds a request header.
UrlRequest.Builder addRequestAnnotation(Object annotation)
Associates the annotation object with this request.
abstract UrlRequest.Builder allowDirectExecutor()
Marks that the executors this request will use to notify callbacks (for UploadDataProviders and UrlRequest.Callbacks) is intentionally performing inline execution, like Guava's directExecutor or ThreadPoolExecutor.CallerRunsPolicy.
UrlRequest.Builder bindToNetwork(long networkHandle)
Binds the request to the specified network handle.
abstract UrlRequest build()
Creates a UrlRequest using configuration within this UrlRequest.Builder.
abstract UrlRequest.Builder disableCache()
Disables cache for the request.
abstract UrlRequest.Builder setHttpMethod(String method)
Sets the HTTP method verb to use for this request.
abstract UrlRequest.Builder setPriority(int priority)
Sets priority of the request which should be one of the REQUEST_PRIORITY_* values.
UrlRequest.Builder setRequestFinishedListener(RequestFinishedInfo.Listener listener)
Sets a listener that gets invoked after onCanceled(), onFailed() or onSucceeded() return.
UrlRequest.Builder setTrafficStatsTag(int tag)
Sets TrafficStats tag to use when accounting socket traffic caused by this request.
UrlRequest.Builder setTrafficStatsUid(int uid)
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.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int REQUEST_PRIORITY_HIGHEST

Highest request priority. Passed to setPriority(int).

Constant Value: 4 (0x00000004)

public static final int REQUEST_PRIORITY_IDLE

Lowest request priority. Passed to setPriority(int).

Constant Value: 0 (0x00000000)

public static final int REQUEST_PRIORITY_LOW

Low request priority. Passed to setPriority(int).

Constant Value: 2 (0x00000002)

public static final int REQUEST_PRIORITY_LOWEST

Very low request priority. Passed to setPriority(int).

Constant Value: 1 (0x00000001)

public static final int REQUEST_PRIORITY_MEDIUM

Medium request priority. Passed to setPriority(int). This is the default priority given to the request.

Constant Value: 3 (0x00000003)

Public Constructors

public UrlRequest.Builder ()

Public Methods

public abstract UrlRequest.Builder addHeader (String header, String value)

Adds a request header.

Parameters
header String: header name.
value String: header value.
Returns
UrlRequest.Builder the builder to facilitate chaining.

public UrlRequest.Builder addRequestAnnotation (Object annotation)

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

Parameters
annotation Object: an object to pass on to the RequestFinishedInfo.Listener with a RequestFinishedInfo.
Returns
UrlRequest.Builder the builder to facilitate chaining.

public abstract UrlRequest.Builder allowDirectExecutor ()

Marks that the executors this request will use to notify callbacks (for UploadDataProviders and UrlRequest.Callbacks) is intentionally performing inline execution, like Guava's directExecutor or ThreadPoolExecutor.CallerRunsPolicy.

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.

Returns
UrlRequest.Builder

public UrlRequest.Builder bindToNetwork (long networkHandle)

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
UrlRequest.Builder the builder to facilitate chaining.

public abstract UrlRequest build ()

Creates a UrlRequest using configuration within this UrlRequest.Builder. The returned UrlRequest can then be started by calling start().

Returns
UrlRequest constructed UrlRequest using configuration within this UrlRequest.Builder.

public abstract UrlRequest.Builder disableCache ()

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

Returns
UrlRequest.Builder the builder to facilitate chaining.

public abstract UrlRequest.Builder setHttpMethod (String method)

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".
Returns
UrlRequest.Builder the builder to facilitate chaining.

public abstract UrlRequest.Builder setPriority (int priority)

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.
Returns
UrlRequest.Builder the builder to facilitate chaining.

public UrlRequest.Builder setRequestFinishedListener (RequestFinishedInfo.Listener listener)

Sets a listener that gets invoked after onCanceled(), onFailed() or onSucceeded() return.

The listener is invoked with the request finished info on an Executor provided by getExecutor().

Parameters
listener RequestFinishedInfo.Listener: the listener for finished requests.
Returns
UrlRequest.Builder the builder to facilitate chaining.

public UrlRequest.Builder setTrafficStatsTag (int tag)

Sets TrafficStats tag to use when accounting socket traffic caused by this request. See 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 DownloadManager when performing traffic on behalf of an application.
Returns
UrlRequest.Builder the builder to facilitate chaining.

public UrlRequest.Builder setTrafficStatsUid (int uid)

Sets specific UID to use when accounting socket traffic caused by this request. See 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
UrlRequest.Builder the builder to facilitate chaining.

public abstract UrlRequest.Builder setUploadDataProvider (UploadDataProvider uploadDataProvider, Executor executor)

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.
executor Executor: All uploadDataProvider methods will be invoked using this Executor. May optionally be the same Executor the request itself is using.
Returns
UrlRequest.Builder the builder to facilitate chaining.