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 UrlRequests.

abstract

Users of the HTTP stack extend this class to receive callbacks indicating the progress of a UrlRequest being processed.

open

Request status values returned by getStatus.

abstract

Listener interface used with getStatus to receive the status of a UrlRequest.

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

Cancels the request.

abstract Unit

Follows a pending redirect.

abstract HeaderBlock

See UrlRequest.Builder#addHeader(String, String)

abstract String?

See UrlRequest.Builder#setHttpMethod(String).

abstract Int

See Builder#setPriority(int)

abstract Unit

Queries the status of the request.

abstract Int

See Builder#setTrafficStatsTag(int)

abstract Int

See Builder#setTrafficStatsUid(int)

abstract Boolean

See Builder#setTrafficStatsTag(int)

abstract Boolean

See Builder#setTrafficStatsUid(int)

abstract Boolean

See Builder#setCacheDisabled(boolean)

abstract Boolean

See UrlRequest.Builder#setDirectExecutorAllowed(boolean)

abstract Boolean

Returns true if the request was successfully started and is now finished (completed, canceled, or failed).

abstract Unit
read(buffer: ByteBuffer)

Attempts to read part of the response body into the provided buffer.

abstract Unit

Starts the request, all callbacks go to Callback.

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

See Builder#setPriority(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

See Builder#setTrafficStatsTag(int)

getTrafficStatsUid

abstract fun getTrafficStatsUid(): Int

See Builder#setTrafficStatsUid(int)

hasTrafficStatsTag

abstract fun hasTrafficStatsTag(): Boolean

See Builder#setTrafficStatsTag(int)

hasTrafficStatsUid

abstract fun hasTrafficStatsUid(): Boolean

See Builder#setTrafficStatsUid(int)

isCacheDisabled

abstract fun isCacheDisabled(): Boolean

See Builder#setCacheDisabled(boolean)

isDirectExecutorAllowed

abstract fun isDirectExecutorAllowed(): Boolean

See UrlRequest.Builder#setDirectExecutorAllowed(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.