HttpEngine
public
abstract
class
HttpEngine
extends Object
java.lang.Object | |
↳ | android.net.http.HttpEngine |
An engine to process UrlRequest
s, 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 |
Public methods | |
---|---|
void
|
bindToNetwork(Network network)
Binds the engine to the specified network. |
abstract
URLStreamHandlerFactory
|
createUrlStreamHandlerFactory()
Creates a |
static
String
|
getVersionString()
|
abstract
BidirectionalStream.Builder
|
newBidirectionalStreamBuilder(String url, Executor executor, BidirectionalStream.Callback callback)
Creates a builder for |
abstract
UrlRequest.Builder
|
newUrlRequestBuilder(String url, Executor executor, UrlRequest.Callback callback)
Creates a builder for |
abstract
URLConnection
|
openConnection(URL url)
Establishes a new connection to the resource specified by the |
abstract
void
|
shutdown()
Shuts down the |
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:
- the HTTP cache installed via
HttpResponseCache.install()
- the HTTP authentication method installed via
Authenticator.setDefault(Authenticator)
- the HTTP cookie storage installed via
CookieHandler.setDefault(CookieHandler)
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
:
- the HTTPS hostname verifier installed via
HttpsURLConnection.setDefaultHostnameVerifier()
- the HTTPS socket factory installed via
HttpsURLConnection.setDefaultSSLSocketFactory()
Returns | |
---|---|
URLStreamHandlerFactory |
an URLStreamHandlerFactory instance implemented by this
HttpEngine .
This value cannot be null . |
getVersionString
public static String getVersionString ()
Returns | |
---|---|
String |
a human-readable version string of the engine.
This value cannot be null . |
newBidirectionalStreamBuilder
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
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
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
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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.