HttpEngine


public abstract class HttpEngine
extends Object

java.lang.Object
   ↳ 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

class HttpEngine.Builder

A builder for HttpEngines, which allows runtime configuration of HttpEngine

Public methods

void bindToNetwork(Network network)

Binds the engine to the specified network.

abstract URLStreamHandlerFactory createUrlStreamHandlerFactory()

Creates a URLStreamHandlerFactory to handle HTTP and HTTPS traffic.

static String getVersionString()
abstract BidirectionalStream.Builder newBidirectionalStreamBuilder(String url, Executor executor, BidirectionalStream.Callback callback)

Creates a builder for BidirectionalStream objects.

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

Creates a builder for UrlRequest.

abstract URLConnection openConnection(URL url)

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

abstract void shutdown()

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

Inherited methods

Public methods

bindToNetwork

Added in API level 34
Also in S Extensions 7
public void bindToNetwork (Network network)

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

Added in API level 34
Also in S Extensions 7
public abstract URLStreamHandlerFactory createUrlStreamHandlerFactory ()

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 URL#openConnection.

This 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:

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

getVersionString

Added in API level 34
Also in S Extensions 7
public static String getVersionString ()

Returns
String a human-readable version string of the engine. This value cannot be null.

newBidirectionalStreamBuilder

Added in API level 34
Also in S Extensions 7
public abstract BidirectionalStream.Builder newBidirectionalStreamBuilder (String url, 
                Executor executor, 
                BidirectionalStream.Callback callback)

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.

Returns
BidirectionalStream.Builder the created builder. This value cannot be null.

newUrlRequestBuilder

Added in API level 34
Also in S Extensions 7
public abstract UrlRequest.Builder newUrlRequestBuilder (String url, 
                Executor executor, 
                UrlRequest.Callback callback)

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.

Returns
UrlRequest.Builder This value cannot be null.

openConnection

Added in API level 34
Also in S Extensions 7
public abstract URLConnection openConnection (URL url)

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

Note: This 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.

Returns
URLConnection an HttpURLConnection instance implemented by this HttpEngine. This value cannot be null.

Throws
IOException if an error occurs while opening the connection.

shutdown

Added in API level 34
Also in S Extensions 7
public abstract void shutdown ()

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.