Package io.meeds.commons.http
Class SafeFetchPolicyBuilder
java.lang.Object
io.meeds.commons.http.SafeFetchPolicyBuilder
Builds a
SafeFetchPolicy, starting from the defaults and refusing
what no policy may hold: a scheme the HTTP client does not speak, a port
outside 1-65535, a non-positive limit or timeout, a timeout over an hour.-
Method Summary
Modifier and TypeMethodDescriptionacceptedContentTypes(Collection<String> contentTypes) Sets the media types an answer may declare; an answer declaring another, or none, is refused before its body is read.allowedPorts(String ports, Collection<Integer> fallback) Reads a comma-separated list of ports, ignoring what is not one — a word, a number outside 1-65535, however many digits it has — as a deployment property states them; falls back to the given set when the list names no usable port.allowedPorts(Collection<Integer> ports) Sets the ports a URL may reach, the implicit default ports included.allowedSchemes(Collection<String> schemes) Sets the schemes a URL may use, withinSafeFetchPolicy.HTTP_SCHEMES.anyPort()Lets a URL reach any port.build()connectTimeout(Duration timeout) Sets the longest wait for a connection.Allows https only.internalAddressesAllowed(boolean allowed) Lets the fetcher reach internal addresses: a deployment's opt-out.maxBytes(long bytes) Sets the largest body read, in bytes: a ceiling a request may lower, never raise.maxConnections(int total, int perRoute) Sets the HTTP client's connection pool bounds.maxRedirects(int redirects) Sets the most redirects followed; zero follows none.Names the fetcher, and so its deadline thread.readTimeout(Duration timeout) Sets the longest wait between two reads.resolver(HostResolver hostResolver) Replaces name resolution: the seam of the tests, a table of names.totalTimeout(Duration timeout) Sets the longest read of a URL, redirects included, enforced by cancelling the request.Sets the User-Agent sent with every request.
-
Method Details
-
name
Names the fetcher, and so its deadline thread.- Parameters:
fetcherName- the name- Returns:
- this builder
-
userAgent
Sets the User-Agent sent with every request.- Parameters:
agent- the header value- Returns:
- this builder
-
allowedSchemes
Sets the schemes a URL may use, withinSafeFetchPolicy.HTTP_SCHEMES.- Parameters:
schemes- the schemes, case ignored- Returns:
- this builder
-
httpsOnly
Allows https only.- Returns:
- this builder
-
allowedPorts
Sets the ports a URL may reach, the implicit default ports included.- Parameters:
ports- the ports, each in 1-65535- Returns:
- this builder
-
allowedPorts
Reads a comma-separated list of ports, ignoring what is not one — a word, a number outside 1-65535, however many digits it has — as a deployment property states them; falls back to the given set when the list names no usable port.- Parameters:
ports- the list, such as80,443,8443fallback- the ports when the list names none- Returns:
- this builder
-
anyPort
Lets a URL reach any port. Stated, never implied: an empty port set is refused, not read as this.- Returns:
- this builder
-
internalAddressesAllowed
Lets the fetcher reach internal addresses: a deployment's opt-out.- Parameters:
allowed- whether they may be reached- Returns:
- this builder
-
acceptedContentTypes
Sets the media types an answer may declare; an answer declaring another, or none, is refused before its body is read. Empty, the default, accepts any. A request may narrow this set, never widen it.- Parameters:
contentTypes- the media types, without parameters, case ignored- Returns:
- this builder
-
maxBytes
Sets the largest body read, in bytes: a ceiling a request may lower, never raise.- Parameters:
bytes- the limit, positive- Returns:
- this builder
-
maxRedirects
Sets the most redirects followed; zero follows none.- Parameters:
redirects- the limit, zero or more- Returns:
- this builder
-
connectTimeout
Sets the longest wait for a connection.- Parameters:
timeout- the wait, positive and at most one hour- Returns:
- this builder
-
readTimeout
Sets the longest wait between two reads.- Parameters:
timeout- the wait, positive and at most one hour- Returns:
- this builder
-
totalTimeout
Sets the longest read of a URL, redirects included, enforced by cancelling the request.- Parameters:
timeout- the deadline, positive and at most one hour- Returns:
- this builder
-
maxConnections
Sets the HTTP client's connection pool bounds.- Parameters:
total- the most connections kept open, positiveperRoute- the most connections kept open to one host, positive- Returns:
- this builder
-
resolver
Replaces name resolution: the seam of the tests, a table of names. Every address it answers is still judged by the guard, so it cannot open what the policy refuses.- Parameters:
hostResolver- the resolver- Returns:
- this builder
-
build
- Returns:
- the policy
-