UrlRequest

abstract class UrlRequest


Controls an HTTP request (GET, PUT, POST etc). Created by UrlRequest.Builder, which can be obtained by calling newUrlRequestBuilder. Note: All methods must be called on the Executor passed to newUrlRequestBuilder.

Summary

Nested types

abstract class UrlRequest.Builder

Builder for UrlRequests.

abstract class UrlRequest.Callback

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

An annotation for APIs which are not considered stable yet.

Request status values returned by getStatus.

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

Public constructors

Public functions

abstract Unit

Cancels the request.

abstract Unit

Follows a pending redirect.

abstract Unit

Queries the status of the request.

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.

Public constructors

UrlRequest

UrlRequest()

Public functions

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().

getStatus

abstract fun getStatus(listener: UrlRequest.StatusListener!): Unit

Queries the status of the request.

Parameters
listener: UrlRequest.StatusListener!

a StatusListener that will be invoked with the request's current status. listener will be invoked back on the Executor passed in when the request was created.

isDone

abstract fun isDone(): Boolean

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

Returns
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'sonReadCompleted() 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.

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.