HttpEngine


abstract class HttpEngine
kotlin.Any
   ↳ android.net.http.HttpEngine

An engine to process UrlRequests, which uses the best HTTP stack available on the current platform. An instance of this class can be created using Builder.

Summary

Nested classes
open

A builder for HttpEngines, which allows runtime configuration of HttpEngine.

Public methods
open Unit

Binds the engine to the specified network.

abstract URLStreamHandlerFactory

Creates a URLStreamHandlerFactory to handle HTTP and HTTPS traffic.

open static String

abstract BidirectionalStream.Builder

Creates a builder for BidirectionalStream objects.

abstract UrlRequest.Builder

Creates a builder for UrlRequest.

abstract URLConnection

Establishes a new connection to the resource specified by the URL url.

abstract Unit

Shuts down the HttpEngine if there are no active requests, otherwise throws an exception.

Public methods

bindToNetwork

open fun bindToNetwork(network: Network?): Unit

Binds the engine to the specified network. All requests created through this engine will use the network associated to this handle. If this network disconnects all requests will fail, the exact error will depend on the stage of request processing when the network disconnects.

Parameters
network Network?: the network to bind the engine to. Specify null to unbind.

createUrlStreamHandlerFactory

abstract fun createUrlStreamHandlerFactory(): URLStreamHandlerFactory

Creates a URLStreamHandlerFactory to handle HTTP and HTTPS traffic. An instance of this class can be installed via URL#setURLStreamHandlerFactory thus using this HttpEngine by default for all requests created via java.net.URL#openConnection.

This java.net.HttpURLConnection implementation does not implement all features offered by the API:

While we support and encourages requests using the HTTPS protocol, we don't provide support for the HttpsURLConnection API. This lack of support also includes not using certain HTTPS features provided via HttpsURLConnection:

Return
URLStreamHandlerFactory an URLStreamHandlerFactory instance implemented by this HttpEngine. This value cannot be null.

getVersionString

open static fun getVersionString(): String
Return
String a human-readable version string of the engine. This value cannot be null.

newBidirectionalStreamBuilder

abstract fun newBidirectionalStreamBuilder(
    url: String,
    executor: Executor,
    callback: BidirectionalStream.Callback
): BidirectionalStream.Builder

Creates a builder for BidirectionalStream objects. All callbacks for generated BidirectionalStream objects will be invoked on executor. executor must not run tasks on the current thread, otherwise the networking operations may block and exceptions may be thrown at shutdown time.

Parameters
url String: URL for the generated streams. This value cannot be null.
executor Executor: the Executor on which callback methods will be invoked. This value cannot be null.
callback BidirectionalStream.Callback: the BidirectionalStream.Callback object that gets invoked upon different events occurring. This value cannot be null.
Return
BidirectionalStream.Builder the created builder. This value cannot be null.

newUrlRequestBuilder

abstract fun newUrlRequestBuilder(
    url: String,
    executor: Executor,
    callback: UrlRequest.Callback
): UrlRequest.Builder

Creates a builder for UrlRequest. All callbacks for generated UrlRequest objects will be invoked on executor's threads. executor must not run tasks on the thread calling Executor#execute to prevent blocking networking operations and causing exceptions during shutdown.

Parameters
url String: URL for the generated requests. This value cannot be null.
executor Executor: Executor on which all callbacks will be invoked. This value cannot be null.
callback UrlRequest.Callback: callback object that gets invoked on different events. This value cannot be null.
Return
UrlRequest.Builder This value cannot be null.

openConnection

abstract fun openConnection(url: URL): URLConnection

Establishes a new connection to the resource specified by the URL url.

Note: This java.net.HttpURLConnection implementation is subject to certain limitations, see createUrlStreamHandlerFactory for details.

Parameters
url URL: URL of resource to connect to. This value cannot be null.
Return
URLConnection an java.net.HttpURLConnection instance implemented by this HttpEngine. This value cannot be null.
Exceptions
java.io.IOException if an error occurs while opening the connection.

shutdown

abstract fun shutdown(): Unit

Shuts down the HttpEngine if there are no active requests, otherwise throws an exception. Cannot be called on network thread - the thread the HTTP stack calls into Executor on (which is different from the thread the Executor invokes callbacks on). May block until all the HttpEngine resources have been cleaned up.