UrlRequest.Callback

abstract class UrlRequest.Callback

Known direct subclasses
ImplicitFlowControlCallback

An implementation of UrlRequest.Callback that takes away the difficulty of managing the request lifecycle away, and automatically proceeds to read the response entirely.

Known indirect subclasses
ByteArrayCronetCallback

A specialization of InMemoryTransformCronetCallback which returns the body bytes verbatim without any interpretation.

InMemoryTransformCronetCallback

An abstract Cronet callback that reads the entire body to memory and optionally deserializes the body before passing it back to the issuer of the HTTP request.

JsonCronetCallback

A specialization of InMemoryTransformCronetCallback that interprets the response body as JSON.

StringCronetCallback

A specialization of InMemoryTransformCronetCallback that interprets the response body as a string.


Users of Cronet extend this class to receive callbacks indicating the progress of a UrlRequest being processed. An instance of this class is passed in to UrlRequest.Builder's constructor when constructing the UrlRequest.

Note: All methods will be invoked on the thread of the java.util.concurrent.Executor used during construction of the UrlRequest.

Summary

Public constructors

Public functions

Unit
onCanceled(request: UrlRequest!, info: UrlResponseInfo!)

Invoked if request was canceled via cancel.

abstract Unit
onFailed(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    error: CronetException!
)

Invoked if request failed for any reason after start.

abstract Unit
onReadCompleted(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    byteBuffer: ByteBuffer!
)

Invoked whenever part of the response body has been read.

abstract Unit
onRedirectReceived(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    newLocationUrl: String!
)

Invoked whenever a redirect is encountered.

abstract Unit

Invoked when the final set of headers, after all redirects, is received.

abstract Unit
onSucceeded(request: UrlRequest!, info: UrlResponseInfo!)

Invoked when request is completed successfully.

Public constructors

Callback

Callback()

Public functions

onCanceled

fun onCanceled(request: UrlRequest!, info: UrlResponseInfo!): Unit

Invoked if request was canceled via cancel. Once invoked, no other Callback methods will be invoked. Default implementation takes no action.

Parameters
request: UrlRequest!

Request that was canceled.

info: UrlResponseInfo!

Response information. May be null if no response was received.

onFailed

abstract fun onFailed(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    error: CronetException!
): Unit

Invoked if request failed for any reason after start. Once invoked, no other Callback methods will be invoked. error provides information about the failure.

Parameters
request: UrlRequest!

Request that failed.

info: UrlResponseInfo!

Response information. May be null if no response was received.

error: CronetException!

information about error.

onReadCompleted

abstract fun onReadCompleted(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    byteBuffer: ByteBuffer!
): Unit

Invoked whenever part of the response body has been read. Only part of the buffer may be populated, even if the entire response body has not yet been consumed. With the exception of onCanceled(), no other Callback method will be invoked for the request, including onSucceeded() and onFailed(), until UrlRequest.read() is called to attempt to continue reading the response body.

Parameters
request: UrlRequest!

Request that received data.

info: UrlResponseInfo!

Response information.

byteBuffer: ByteBuffer!

The buffer that was passed in to UrlRequest.read(), now containing the received data. The buffer's position is updated to the end of the received data. The buffer's limit is not changed.

Throws
java.lang.Exception

if an error occurs while processing a read completion. onFailed will be called with the thrown exception set as the cause of the CallbackException.

onRedirectReceived

abstract fun onRedirectReceived(
    request: UrlRequest!,
    info: UrlResponseInfo!,
    newLocationUrl: String!
): Unit

Invoked whenever a redirect is encountered. This will only be invoked between the call to start and onResponseStarted(). The body of the redirect response, if it has one, will be ignored. The redirect will not be followed until the URLRequest's followRedirect method is called, either synchronously or asynchronously.

Parameters
request: UrlRequest!

Request being redirected.

info: UrlResponseInfo!

Response information.

newLocationUrl: String!

Location where request is redirected.

Throws
java.lang.Exception

if an error occurs while processing a redirect. onFailed will be called with the thrown exception set as the cause of the CallbackException.

onResponseStarted

abstract fun onResponseStarted(request: UrlRequest!, info: UrlResponseInfo!): Unit

Invoked when the final set of headers, after all redirects, is received. Will only be invoked once for each request. With the exception of onCanceled(), no other Callback method will be invoked for the request, including onSucceeded() and onFailed(), until UrlRequest.read() is called to attempt to start reading the response body.

Parameters
request: UrlRequest!

Request that started to get response.

info: UrlResponseInfo!

Response information.

Throws
java.lang.Exception

if an error occurs while processing response start. onFailed will be called with the thrown exception set as the cause of the CallbackException.

onSucceeded

abstract fun onSucceeded(request: UrlRequest!, info: UrlResponseInfo!): Unit

Invoked when request is completed successfully. Once invoked, no other Callback methods will be invoked.

Parameters
request: UrlRequest!

Request that succeeded.

info: UrlResponseInfo!

Response information.