Package io.meeds.commons.http
Record Class SafeFetchRequest
java.lang.Object
java.lang.Record
io.meeds.commons.http.SafeFetchRequest
- Record Components:
uri- the URL to readaccept- theAcceptheader sent, null for noneifNoneMatch- theIf-None-Matchheader sent, null for noneifModifiedSince- theIf-Modified-Sinceheader sent, null for noneacceptedContentTypes- the media types this read accepts, within the policy's when the policy names some; null keeps the policy's, and an empty set is refusedmaxBytes- the most bytes this read takes, capped at the policy's; zero or less keeps the policy'struncateAtLimit- whether a body past the limit is cut at it and returned, instead of refused: for a page whose head comes first, never for an image, useless cut
public record SafeFetchRequest(URI uri, String accept, String ifNoneMatch, String ifModifiedSince, Set<String> acceptedContentTypes, long maxBytes, boolean truncateAtLimit)
extends Record
One read of a URL by
SafeHttpFetcher: a GET, with the headers it
sends and how it narrows the fetcher's SafeFetchPolicy. A request
never widens the policy: its body limit is capped at the policy's, and its
media types are kept only where the policy accepts them too. Built from
get(URI) and the with methods; immutable. A header value
carrying a line break or another control character than a horizontal tab
is refused, so that no value can add a header of its own.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaccept()Returns the value of theacceptrecord component.Returns the value of theacceptedContentTypesrecord component.final booleanIndicates whether some other object is "equal to" this one.static SafeFetchRequestA plain GET under the fetcher's policy.final inthashCode()Returns a hash code value for this object.Returns the value of theifModifiedSincerecord component.Returns the value of theifNoneMatchrecord component.longmaxBytes()Returns the value of themaxBytesrecord component.final StringtoString()Returns a string representation of this record class.booleanReturns the value of thetruncateAtLimitrecord component.The same read, a body past the limit cut at it and returned rather than refused.uri()Returns the value of theurirecord component.withAccept(String acceptHeader) The same read with anAcceptheader.withAcceptedContentTypes(Collection<String> contentTypes) The same read accepting these media types only, within the policy's when the policy names some: a type the policy refuses stays refused.withMaxBytes(long limit) The same read taking at most this many bytes, or the policy's limit when that is lower.withValidators(String etag, String lastModified) The same read made conditional on the validators of a previous one; a server answering 304 gives a not-modified response.
-
Constructor Details
-
SafeFetchRequest
public SafeFetchRequest(URI uri, String accept, String ifNoneMatch, String ifModifiedSince, Set<String> acceptedContentTypes, long maxBytes, boolean truncateAtLimit) Checks the request and normalizes its media types.- Parameters:
uri- the URL to readaccept- theAcceptheader sentifNoneMatch- theIf-None-Matchheader sentifModifiedSince- theIf-Modified-Sinceheader sentacceptedContentTypes- the media types acceptedmaxBytes- the most bytes readtruncateAtLimit- whether a longer body is cut rather than refused- Throws:
IllegalArgumentException- when a header value carries a control character, or the media types name none
-
-
Method Details
-
get
A plain GET under the fetcher's policy.- Parameters:
uri- the URL to read- Returns:
- the request
-
withAccept
The same read with anAcceptheader.- Parameters:
acceptHeader- the header value- Returns:
- the request
-
withValidators
The same read made conditional on the validators of a previous one; a server answering 304 gives a not-modified response.- Parameters:
etag- the entity tag of the previous read, or nulllastModified- theLast-Modifiedof the previous read, or null- Returns:
- the request
- Throws:
IllegalArgumentException- when a value carries a control character
-
withAcceptedContentTypes
The same read accepting these media types only, within the policy's when the policy names some: a type the policy refuses stays refused.- Parameters:
contentTypes- the media types, without parameters, case ignored; at least one- Returns:
- the request
- Throws:
IllegalArgumentException- when the set names no media type
-
withMaxBytes
The same read taking at most this many bytes, or the policy's limit when that is lower.- Parameters:
limit- the limit, positive- Returns:
- the request
-
truncatedAtLimit
The same read, a body past the limit cut at it and returned rather than refused.- Returns:
- the request
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
uri
Returns the value of theurirecord component.- Returns:
- the value of the
urirecord component
-
accept
Returns the value of theacceptrecord component.- Returns:
- the value of the
acceptrecord component
-
ifNoneMatch
Returns the value of theifNoneMatchrecord component.- Returns:
- the value of the
ifNoneMatchrecord component
-
ifModifiedSince
Returns the value of theifModifiedSincerecord component.- Returns:
- the value of the
ifModifiedSincerecord component
-
acceptedContentTypes
Returns the value of theacceptedContentTypesrecord component.- Returns:
- the value of the
acceptedContentTypesrecord component
-
maxBytes
public long maxBytes()Returns the value of themaxBytesrecord component.- Returns:
- the value of the
maxBytesrecord component
-
truncateAtLimit
public boolean truncateAtLimit()Returns the value of thetruncateAtLimitrecord component.- Returns:
- the value of the
truncateAtLimitrecord component
-