Stay organized with collections Save and categorize content based on your preferences.

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 UrlRequest.Builder newUrlRequestBuilder(String url, UrlRequest.Callback callback, Executor executor)

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

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

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.

getVersionString

public static String getVersionString ()

Returns
String a human-readable version string of the engine.

newUrlRequestBuilder

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

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.

callback UrlRequest.Callback: callback object that gets invoked on different events.

executor Executor: Executor on which all callbacks will be invoked.

Returns
UrlRequest.Builder

openConnection

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.

Returns
URLConnection an HttpURLConnection instance implemented by this HttpEngine.

Throws
IOException if an error occurs while opening the connection.

shutdown

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.