Class CacheControlHeaderParser
This class is thread-safe and has a singleton instance (INSTANCE).
The parseResponse(Iterator) method takes an HTTP header and returns a ResponseCacheControl object containing
the relevant caching directives. The header can be either a FormattedHeader object, which contains a
pre-parsed CharArrayBuffer, or a plain Header object, in which case the value will be parsed and
stored in a new CharArrayBuffer.
This parser only supports two directives: "max-age" and "s-maxage". If either of these directives are present in the
header, their values will be parsed and stored in the ResponseCacheControl object. If both directives are
present, the value of "s-maxage" takes precedence.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final charstatic final CacheControlHeaderParserThe singleton instance of this parser.private static final org.slf4j.LoggerThe logger for this class.private static final org.apache.hc.core5.util.Tokenizer.DelimiterThe set of characters that can delimit a token in the header.private final org.apache.hc.core5.util.TokenizerThe token parser used to extract values from the header.private static final org.apache.hc.core5.util.Tokenizer.DelimiterThe set of characters that can delimit a value in the header. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a new instance of this parser. -
Method Summary
Modifier and TypeMethodDescriptionvoidparse(Iterator<org.apache.hc.core5.http.Header> headerIterator, BiConsumer<String, String> consumer) final ResponseCacheControlparse(HttpCacheEntry cacheEntry) final RequestCacheControlparse(org.apache.hc.core5.http.HttpRequest request) final ResponseCacheControlparse(org.apache.hc.core5.http.HttpResponse response) final RequestCacheControlparseRequest(Iterator<org.apache.hc.core5.http.Header> headerIterator) Parses the specified request header and returns a newRequestCacheControlinstance containing the relevant caching directives.final ResponseCacheControlparseResponse(Iterator<org.apache.hc.core5.http.Header> headerIterator) Parses the specified response header and returns a newResponseCacheControlinstance containing the relevant caching directives.private static longparseSeconds(String name, String value)
-
Field Details
-
INSTANCE
The singleton instance of this parser. -
LOG
private static final org.slf4j.Logger LOGThe logger for this class. -
EQUAL_CHAR
private static final char EQUAL_CHAR- See Also:
-
TOKEN_DELIMS
private static final org.apache.hc.core5.util.Tokenizer.Delimiter TOKEN_DELIMSThe set of characters that can delimit a token in the header. -
VALUE_DELIMS
private static final org.apache.hc.core5.util.Tokenizer.Delimiter VALUE_DELIMSThe set of characters that can delimit a value in the header. -
tokenParser
private final org.apache.hc.core5.util.Tokenizer tokenParserThe token parser used to extract values from the header.
-
-
Constructor Details
-
CacheControlHeaderParser
protected CacheControlHeaderParser()Constructs a new instance of this parser.
-
-
Method Details
-
parse
public void parse(Iterator<org.apache.hc.core5.http.Header> headerIterator, BiConsumer<String, String> consumer) -
parseResponse
public final ResponseCacheControl parseResponse(Iterator<org.apache.hc.core5.http.Header> headerIterator) Parses the specified response header and returns a newResponseCacheControlinstance containing the relevant caching directives.The returned
ResponseCacheControlinstance will contain the values for "max-age" and "s-maxage" caching directives parsed from the input header. If the input header does not contain any caching directives or if the directives are malformed, the returnedResponseCacheControlinstance will have default values for "max-age" and "s-maxage" (-1).- Parameters:
headerIterator- the header to parse, cannot benull- Returns:
- a new
ResponseCacheControlinstance containing the relevant caching directives parsed from the response header - Throws:
IllegalArgumentException- if the input header isnull
-
parse
-
parse
-
parseRequest
public final RequestCacheControl parseRequest(Iterator<org.apache.hc.core5.http.Header> headerIterator) Parses the specified request header and returns a newRequestCacheControlinstance containing the relevant caching directives.- Parameters:
headerIterator- the header to parse, cannot benull- Returns:
- a new
RequestCacheControlinstance containing the relevant caching directives parsed from the request header - Throws:
IllegalArgumentException- if the input header isnull
-
parse
-
parseSeconds
-