UrlRequest
abstract class UrlRequest
kotlin.Any | |
↳ | android.net.http.UrlRequest |
Controls an HTTP request (GET, PUT, POST etc). Created by UrlRequest.Builder
, which can be obtained by calling HttpEngine.newUrlRequestBuilder
. Note: All methods must be called on the Executor
passed to HttpEngine.newUrlRequestBuilder
.
Summary
Nested classes | |
---|---|
abstract |
Builder for |
abstract |
Users of the HTTP stack extend this class to receive callbacks indicating the progress of a |
open |
Request status values returned by |
abstract |
Listener interface used with |
Constants | |
---|---|
static Int |
Highest request priority. |
static Int |
Lowest request priority. |
static Int |
Low request priority. |
static Int |
Very low request priority. |
static Int |
Medium request priority. |
Public methods | |
---|---|
abstract Unit |
cancel() Cancels the request. |
abstract Unit |
Follows a pending redirect. |
abstract HeaderBlock | |
abstract String? | |
abstract Int | |
abstract Unit |
getStatus(listener: UrlRequest.StatusListener) Queries the status of the request. |
abstract Int | |
abstract Int | |
abstract Boolean | |
abstract Boolean | |
abstract Boolean | |
abstract Boolean | |
abstract Boolean |
isDone() Returns |
abstract Unit |
read(buffer: ByteBuffer) Attempts to read part of the response body into the provided buffer. |
abstract Unit |
start() Starts the request, all callbacks go to |
Constants
REQUEST_PRIORITY_HIGHEST
static val REQUEST_PRIORITY_HIGHEST: Int
Highest request priority. Passed to Builder.setPriority
.
Value: 4
REQUEST_PRIORITY_IDLE
static val REQUEST_PRIORITY_IDLE: Int
Lowest request priority. Passed to Builder.setPriority
.
Value: 0
REQUEST_PRIORITY_LOW
static val REQUEST_PRIORITY_LOW: Int
Low request priority. Passed to Builder.setPriority
.
Value: 2
REQUEST_PRIORITY_LOWEST
static val REQUEST_PRIORITY_LOWEST: Int
Very low request priority. Passed to Builder.setPriority
.
Value: 1
REQUEST_PRIORITY_MEDIUM
static val REQUEST_PRIORITY_MEDIUM: Int
Medium request priority. Passed to Builder.setPriority
. This is the default priority given to the request.
Value: 3
Public methods
cancel
abstract fun cancel(): Unit
Cancels the request. Can be called at any time. onCanceled()
will be invoked when cancellation is complete and no further callback methods will be invoked. If the request has completed or has not started, calling cancel()
has no effect and onCanceled()
will not be invoked. If the Executor
passed in during UrlRequest
construction runs tasks on a single thread, and cancel()
is called on that thread, no callback methods (besides onCanceled()
) will be invoked after cancel()
is called. Otherwise, at most one callback method may be invoked after cancel()
has completed.
followRedirect
abstract fun followRedirect(): Unit
Follows a pending redirect. Must only be called at most once for each invocation of onRedirectReceived()
.
getHeaders
abstract fun getHeaders(): HeaderBlock
See UrlRequest.Builder.addHeader(String, String)
Return | |
---|---|
HeaderBlock |
This value cannot be null . |
getHttpMethod
abstract fun getHttpMethod(): String?
See UrlRequest.Builder.setHttpMethod(String)
.
Return | |
---|---|
String? |
This value may be null . |
getPriority
abstract fun getPriority(): Int
getStatus
abstract fun getStatus(listener: UrlRequest.StatusListener): Unit
Queries the status of the request.
This is most useful to query the status of the request before any of the UrlRequest.Callback
methods are called by Cronet.
The listener
will be invoked back on the Executor
passed in when the request was created. While you can assume the callback will be invoked in a timely fashion, the API doesn't make any guarantees about the latency, nor does it specify the order in which the listener and other callbacks will be invoked.
Parameters | |
---|---|
listener |
UrlRequest.StatusListener: a StatusListener that will be invoked with the request's current status. This value cannot be null . |
getTrafficStatsTag
abstract fun getTrafficStatsTag(): Int
getTrafficStatsUid
abstract fun getTrafficStatsUid(): Int
hasTrafficStatsTag
abstract fun hasTrafficStatsTag(): Boolean
hasTrafficStatsUid
abstract fun hasTrafficStatsUid(): Boolean
isCacheDisabled
abstract fun isCacheDisabled(): Boolean
isDirectExecutorAllowed
abstract fun isDirectExecutorAllowed(): Boolean
isDone
abstract fun isDone(): Boolean
Returns true
if the request was successfully started and is now finished (completed, canceled, or failed).
Return | |
---|---|
Boolean |
true if the request was successfully started and is now finished (completed, canceled, or failed). |
read
abstract fun read(buffer: ByteBuffer): Unit
Attempts to read part of the response body into the provided buffer. Must only be called at most once in response to each invocation of the onResponseStarted()
and onReadCompleted()
methods of the Callback
. Each call will result in an asynchronous call to either the Callback's
onReadCompleted()
method if data is read, its onSucceeded()
method if there's no more data to read, or its onFailed()
method if there's an error.
Parameters | |
---|---|
buffer |
ByteBuffer: ByteBuffer to write response body to. Must be a direct ByteBuffer. The embedder must not read or modify buffer's position, limit, or data between its position and limit until the request calls back into the Callback . This value cannot be null . |
start
abstract fun start(): Unit
Starts the request, all callbacks go to Callback
. May only be called once. May not be called if cancel
has been called.