Package io.meeds.commons.http
Class SafeFetchPolicy
java.lang.Object
io.meeds.commons.http.SafeFetchPolicy
What a
SafeHttpFetcher may read and how far it goes: the schemes and
ports a URL may use, whether internal addresses may be reached at all, the
content types accepted, the most bytes read, the most redirects followed,
the timeouts, and the HTTP client's own bounds. Built with
SafeFetchPolicyBuilder; immutable.
The resolver and the two exemptions are the
seams of the tests, so that a stub server on loopback can stand in for a
public one while every other internal address stays refused. The resolver
can be set by anyone, since the guard judges every address it answers; the
exemptions are set only from this package, so a production policy holds
none. The body limit and the accepted content types are ceilings: a
SafeFetchRequest narrows them, never widens them.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationLongest wait for a connection unless the policy says otherwise.static final longLargest body read unless the policy says otherwise, in bytes.static final intMost redirects followed unless the policy says otherwise.static final StringThe name of a fetcher built without one; names its deadline thread.The ports a URL may reach unless the policy says otherwise.static final DurationLongest wait between two reads unless the policy says otherwise.static final DurationLongest read of a URL, redirects included, unless the policy says otherwise.static final StringThe User-Agent sent unless the policy says otherwise.The scheme set a policy may draw from: the HTTP client speaks nothing else. -
Method Summary
Modifier and TypeMethodDescriptionstatic SafeFetchPolicyBuilderbuilder()longintintintgetName()booleanboolean
-
Field Details
-
HTTP_SCHEMES
The scheme set a policy may draw from: the HTTP client speaks nothing else. -
DEFAULT_PORTS
The ports a URL may reach unless the policy says otherwise. -
DEFAULT_MAX_BYTES
public static final long DEFAULT_MAX_BYTESLargest body read unless the policy says otherwise, in bytes.- See Also:
-
DEFAULT_MAX_REDIRECTS
public static final int DEFAULT_MAX_REDIRECTSMost redirects followed unless the policy says otherwise.- See Also:
-
DEFAULT_CONNECT
Longest wait for a connection unless the policy says otherwise. -
DEFAULT_READ
Longest wait between two reads unless the policy says otherwise. -
DEFAULT_TOTAL
Longest read of a URL, redirects included, unless the policy says otherwise. -
DEFAULT_NAME
The name of a fetcher built without one; names its deadline thread.- See Also:
-
DEFAULT_USER_AGENT
The User-Agent sent unless the policy says otherwise.- See Also:
-
-
Method Details
-
builder
- Returns:
- a builder holding the defaults
-
getName
- Returns:
- the fetcher's name, which names its deadline thread
-
getUserAgent
- Returns:
- the User-Agent sent with every request
-
getAllowedSchemes
- Returns:
- the schemes a URL may use, lower-case, within
HTTP_SCHEMES
-
getAllowedPorts
- Returns:
- the ports a URL may reach, implicit default ports included; empty
when
isAnyPortAllowed()
-
isAnyPortAllowed
public boolean isAnyPortAllowed()- Returns:
- whether a URL may reach any port
-
isInternalAddressesAllowed
public boolean isInternalAddressesAllowed()- Returns:
- whether internal addresses may be reached: a deployment's opt-out, false by default
-
getAcceptedContentTypes
- Returns:
- the media types an answer may declare, lower-case and without parameters; empty when any is accepted
-
getMaxBytes
public long getMaxBytes()- Returns:
- the largest body read, in bytes, unless the request says otherwise
-
getMaxRedirects
public int getMaxRedirects()- Returns:
- the most redirects followed
-
getConnectTimeout
- Returns:
- the longest wait for a connection
-
getReadTimeout
- Returns:
- the longest wait between two reads
-
getTotalTimeout
- Returns:
- the longest read of a URL, redirects included
-
getMaxConnectionsTotal
public int getMaxConnectionsTotal()- Returns:
- the most connections the fetcher keeps open
-
getMaxConnectionsPerRoute
public int getMaxConnectionsPerRoute()- Returns:
- the most connections the fetcher keeps open to one host
-
getResolver
- Returns:
- name resolution; the JDK's unless a test says otherwise
-
getExemptHosts
- Returns:
- host names whose addresses are read as public; empty in production
-
getExemptAddresses
- Returns:
- addresses read as public; empty in production
-