Class CacheControlHeaderParser
- java.lang.Object
-
- org.apache.hc.client5.http.impl.cache.CacheControlHeaderParser
-
@Internal @Contract(threading=IMMUTABLE) class CacheControlHeaderParser extends java.lang.ObjectA parser for the HTTP Cache-Control header that can be used to extract information about caching directives.This class is thread-safe and has a singleton instance (
INSTANCE).The
parseResponse(Iterator)method takes an HTTP header and returns aResponseCacheControlobject containing the relevant caching directives. The header can be either aFormattedHeaderobject, which contains a pre-parsedCharArrayBuffer, or a plainHeaderobject, in which case the value will be parsed and stored in a newCharArrayBuffer.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
ResponseCacheControlobject. If both directives are present, the value of "s-maxage" takes precedence.
-
-
Field Summary
Fields Modifier and Type Field Description private static charEQUAL_CHARstatic CacheControlHeaderParserINSTANCEThe singleton instance of this parser.private static org.slf4j.LoggerLOGThe logger for this class.private static org.apache.hc.core5.util.Tokenizer.DelimiterTOKEN_DELIMSThe set of characters that can delimit a token in the header.private org.apache.hc.core5.util.TokenizertokenParserThe token parser used to extract values from the header.private static org.apache.hc.core5.util.Tokenizer.DelimiterVALUE_DELIMSThe set of characters that can delimit a value in the header.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCacheControlHeaderParser()Constructs a new instance of this parser.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidparse(java.util.Iterator<org.apache.hc.core5.http.Header> headerIterator, java.util.function.BiConsumer<java.lang.String,java.lang.String> consumer)ResponseCacheControlparse(HttpCacheEntry cacheEntry)RequestCacheControlparse(org.apache.hc.core5.http.HttpRequest request)ResponseCacheControlparse(org.apache.hc.core5.http.HttpResponse response)RequestCacheControlparseRequest(java.util.Iterator<org.apache.hc.core5.http.Header> headerIterator)Parses the specified request header and returns a newRequestCacheControlinstance containing the relevant caching directives.ResponseCacheControlparseResponse(java.util.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(java.lang.String name, java.lang.String value)
-
-
-
Field Detail
-
INSTANCE
public static final CacheControlHeaderParser INSTANCE
The singleton instance of this parser.
-
LOG
private static final org.slf4j.Logger LOG
The logger for this class.
-
EQUAL_CHAR
private static final char EQUAL_CHAR
- See Also:
- Constant Field Values
-
TOKEN_DELIMS
private static final org.apache.hc.core5.util.Tokenizer.Delimiter TOKEN_DELIMS
The set of characters that can delimit a token in the header.
-
VALUE_DELIMS
private static final org.apache.hc.core5.util.Tokenizer.Delimiter VALUE_DELIMS
The set of characters that can delimit a value in the header.
-
tokenParser
private final org.apache.hc.core5.util.Tokenizer tokenParser
The token parser used to extract values from the header.
-
-
Method Detail
-
parse
public void parse(java.util.Iterator<org.apache.hc.core5.http.Header> headerIterator, java.util.function.BiConsumer<java.lang.String,java.lang.String> consumer)
-
parseResponse
public final ResponseCacheControl parseResponse(java.util.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:
java.lang.IllegalArgumentException- if the input header isnull
-
parse
public final ResponseCacheControl parse(org.apache.hc.core5.http.HttpResponse response)
-
parse
public final ResponseCacheControl parse(HttpCacheEntry cacheEntry)
-
parseRequest
public final RequestCacheControl parseRequest(java.util.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:
java.lang.IllegalArgumentException- if the input header isnull
-
parse
public final RequestCacheControl parse(org.apache.hc.core5.http.HttpRequest request)
-
parseSeconds
private static long parseSeconds(java.lang.String name, java.lang.String value)
-
-