Builder for UrlRequest
s. Allows configuring requests before constructing them
with build()
. The builder can be created by calling
CronetEngine.newUrlRequestBuilder(String, UrlRequest.Callback, Executor)
.
Constant Summary
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 Constructor Summary
Builder()
|
Public Method Summary
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
UploadDataProvider s and UrlRequest.Callback s) is intentionally performing
inline execution, like Guava's directExecutor or
ThreadPoolExecutor.CallerRunsPolicy . |
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. |
abstract UrlRequest.Builder |
setUploadDataProvider(UploadDataProvider uploadDataProvider, Executor executor)
Sets upload data provider.
|
Inherited Method Summary
Constants
public static final int REQUEST_PRIORITY_HIGHEST
Highest request priority. Passed to setPriority(int)
.
public static final int REQUEST_PRIORITY_IDLE
Lowest request priority. Passed to setPriority(int)
.
public static final int REQUEST_PRIORITY_LOW
Low request priority. Passed to setPriority(int)
.
public static final int REQUEST_PRIORITY_LOWEST
Very low request priority. Passed to setPriority(int)
.
public static final int REQUEST_PRIORITY_MEDIUM
Medium request priority. Passed to setPriority(int)
. This is the
default priority given to the request.
Public Constructors
public Builder ()
Public Methods
public abstract UrlRequest.Builder addHeader (String header, String value)
Adds a request header.
Parameters
header | header name. |
---|---|
value | header value. |
Returns
- the builder to facilitate chaining.
public abstract UrlRequest.Builder allowDirectExecutor ()
Marks that 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
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.
public abstract UrlRequest build ()
Creates a UrlRequest
using configuration within this
UrlRequest.Builder
. The returned UrlRequest
can then be started
by calling UrlRequest.start()
.
Returns
- constructed
UrlRequest
using configuration within thisUrlRequest.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
- 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 | "GET", "HEAD", "DELETE", "POST" or "PUT". |
---|
Returns
- 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 | priority of the request which should be one of the
REQUEST_PRIORITY_* values. |
---|
Returns
- 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 | responsible for providing the upload data. |
---|---|
executor | All uploadDataProvider methods will be invoked
using this Executor . May optionally be the same
Executor the request itself is using. |
Returns
- the builder to facilitate chaining.