Class SafeHttpFetcher
- All Implemented Interfaces:
Closeable,AutoCloseable
SafeFetchPolicy: the one place to fetch a user-, sender- or
agent-controlled URL from the server.
Addresses are the SafeAddressGuard's: it is the resolver of
the connection manager (GuardedDnsResolver), so the address of every
connection is judged when the connection is opened — there is one lookup,
and it is the checked one; the guard also checks each URL's shape before it
is requested, and redirects are followed here, one hop at a time, each
target checked again. Bounds: a connect timeout, a read timeout, a
deadline over the whole read — redirects included — enforced by cancelling
the request, a body limit counted on the decoded bytes (a compressed body
cannot inflate past it), a redirect count, and the declared content type
checked before the body is read. A SafeFetchRequest narrows these
bounds, never widens them. Nothing of the platform's goes out: no
cookie store, no credentials, no proxy, no retry. The headers sent are the
HTTP client's own — Host, Connection, the policy's
User-Agent and the Accept-Encoding of the compressions it
decodes — and the ones the request names: Accept,
If-None-Match, If-Modified-Since. Nothing of the URL goes
into a log: it may embed a secret.
Thread-safe; one instance per consumer, closed when the consumer goes. A
closed fetcher refuses every read with an IllegalStateException.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Stops the deadline thread and closes the connections; a read started afterwards is refused.fetch(SafeFetchRequest request) Reads a URL, following redirects within the policy's count, each target checked by the guard before it is requested and judged again by the resolver when its connection opens.Reads a URL with a plain GET under the policy.getGuard()
-
Constructor Details
-
SafeHttpFetcher
The fetcher of a policy.- Parameters:
policy- what may be read and how far the fetcher goes
-
-
Method Details
-
getPolicy
- Returns:
- the policy this fetcher reads under
-
getGuard
- Returns:
- the guard, whose URL rules a caller may apply before a read
-
fetch
Reads a URL with a plain GET under the policy.- Parameters:
uri- the URL- Returns:
- what the server answered
- Throws:
SafeFetchException- with the reason nothing usable was readIllegalStateException- when the fetcher is closed
-
fetch
Reads a URL, following redirects within the policy's count, each target checked by the guard before it is requested and judged again by the resolver when its connection opens.- Parameters:
request- the read- Returns:
- what the server answered
- Throws:
SafeFetchException- with the reason nothing usable was readIllegalStateException- when the fetcher is closed
-
close
public void close()Stops the deadline thread and closes the connections; a read started afterwards is refused.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-