@AnyThread public class GeckoWebExecutor extends Object
WebRequest
and delivering
a WebResponse
to the caller via fetch(WebRequest)
. Example:
final GeckoWebExecutor executor = new GeckoWebExecutor(); final GeckoResult<WebResponse> result = executor.fetch( new WebRequest.Builder("https://example.org/json") .header("Accept", "application/json") .build()); result.then(response -> { // Do something with response });
Modifier and Type | Field and Description |
---|---|
static int |
FETCH_FLAGS_ANONYMOUS
Don't send cookies or other user data along with the request.
|
static int |
FETCH_FLAGS_NO_REDIRECTS
Don't automatically follow redirects.
|
static int |
FETCH_FLAGS_NONE
No special treatment.
|
static int |
FETCH_FLAGS_PRIVATE
Associates this download with the current private browsing session
|
static int |
FETCH_FLAGS_STREAM_FAILURE_TEST
This flag causes a read error in the
WebResponse body. |
Constructor and Description |
---|
GeckoWebExecutor(GeckoRuntime runtime)
Create a new GeckoWebExecutor instance.
|
Modifier and Type | Method and Description |
---|---|
GeckoResult<WebResponse> |
fetch(WebRequest request)
Send the given
WebRequest . |
GeckoResult<WebResponse> |
fetch(WebRequest request,
int flags)
Send the given
WebRequest with specified flags. |
GeckoResult<InetAddress[]> |
resolve(String host)
Resolves the specified host name.
|
void |
speculativeConnect(String uri)
This causes a speculative connection to be made to the host
in the specified URI.
|
public static final int FETCH_FLAGS_NONE
public static final int FETCH_FLAGS_ANONYMOUS
public static final int FETCH_FLAGS_NO_REDIRECTS
public static final int FETCH_FLAGS_PRIVATE
public static final int FETCH_FLAGS_STREAM_FAILURE_TEST
WebResponse
body. Useful for testing.public GeckoWebExecutor(@NonNull GeckoRuntime runtime)
runtime
- A GeckoRuntime instance@NonNull public GeckoResult<WebResponse> fetch(@NonNull WebRequest request)
WebRequest
.request
- A WebRequest
instanceGeckoResult
which will be completed with a WebResponse
. If the
request fails to complete, the GeckoResult
will be completed exceptionally
with a WebRequestError
.IllegalArgumentException
- if request is null or otherwise unusable.@NonNull public GeckoResult<WebResponse> fetch(@NonNull WebRequest request, int flags)
WebRequest
with specified flags.request
- A WebRequest
instanceflags
- The specified flags. One or more of the FETCH_*
flags.GeckoResult
which will be completed with a WebResponse
. If the
request fails to complete, the GeckoResult
will be completed exceptionally
with a WebRequestError
.IllegalArgumentException
- if request is null or otherwise unusable.@NonNull public GeckoResult<InetAddress[]> resolve(@NonNull String host)
host
- An Internet host name, e.g. mozilla.org.GeckoResult
which will be fulfilled with a List
of InetAddress
. In case of failure, the GeckoResult
will be completed exceptionally with a UnknownHostException
.public void speculativeConnect(@NonNull String uri)
uri
- A URI String.