Stay organized with collections Save and categorize content based on your preferences.

UrlRequest.Builder

public static abstract class UrlRequest.Builder
extends Object

java.lang.Object
   ↳ android.net.http.UrlRequest.Builder


Builder for UrlRequests. Allows configuring requests before constructing them with Builder#build. The builder can be created by calling HttpEngine#newUrlRequestBuilder.

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 methods

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

Adds a request header.

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.

abstract UrlRequest.Builder bindToNetwork(Network network)

Binds the request to the specified network.

abstract UrlRequest build()

Creates a UrlRequest using configuration within this 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.

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

Sets upload data provider.

Inherited methods

Constants

REQUEST_PRIORITY_HIGHEST

public static final int REQUEST_PRIORITY_HIGHEST

Highest request priority. Passed to setPriority(int).

Constant Value: 4 (0x00000004)

REQUEST_PRIORITY_IDLE

public static final int REQUEST_PRIORITY_IDLE

Lowest request priority. Passed to setPriority(int).

Constant Value: 0 (0x00000000)

REQUEST_PRIORITY_LOW

public static final int REQUEST_PRIORITY_LOW

Low request priority. Passed to setPriority(int).

Constant Value: 2 (0x00000002)

REQUEST_PRIORITY_LOWEST

public static final int REQUEST_PRIORITY_LOWEST

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

Constant Value: 1 (0x00000001)

REQUEST_PRIORITY_MEDIUM

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 methods

addHeader

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.

allowDirectExecutor

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

bindToNetwork

public abstract UrlRequest.Builder bindToNetwork (Network network)

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.

Returns
UrlRequest.Builder the builder to facilitate chaining.

build

public abstract UrlRequest build ()

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

Returns
UrlRequest constructed UrlRequest using configuration within this Builder.

disableCache

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.

setHttpMethod

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.

setPriority

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.

setUploadDataProvider

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.