Documentation
¶
Overview ¶
Package cachecontrol implements tokenization and parsing of Cache-Control header directives based on a relaxed version of RFC 9111, similar to the implementations in major web browser engines (Chromium, Firefox, Safari).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse parses the given Cache-Control value and returns a sequence of directives.
The parsing uses Tokenize to extract tokens from the given string and tries its best to form directives even from non RFC9111 compliant inputs.
Notably a directive like `directive1=value "with" space,directive2` will _correctly_ parse the first directive with the value `value "with" space`.
Types ¶
type Directive ¶
type Directive struct {
// Name of the directive. May be empty if HasValue is true.
Name string
// Value of the directive, if any. May be empty. Check HasValue to differentiate between an empty and no value.
Value string
// HasValue is true if Value is set.
HasValue bool
}
Directive represents a single Cache-Control directive with optional value.
type Token ¶
type Token struct {
// Type is the type of the token.
Type TokenType
// Start is the byte offset in the input string where the token starts.
Start int
// End is the byte offset in the input string where the token ends.
End int
// Text is the text of the token.
//
// For tokens of type [TokenTypeText], if the parsed text was a quoted string, this contains the unescaped string
// without quotes.
//
// For [TokenTypeComma] and [TokenTypeEquals] this contains a single "," or "=".
//
// For [TokenTypeSpace] this contains the spaces, including control characters.
Text string
}
Token represents a parsed token from a string of Cache-Control directives.
type TokenType ¶
type TokenType uint8
TokenType is an enum of token types as understood by Tokenize.
const ( // TokenTypeInvalid is the zero value of [TokenType] and is not a valid value. // [Tokenize] will never return a token of this type. TokenTypeInvalid TokenType = iota // TokenTypeComma represents a single comma. TokenTypeComma // TokenTypeEquals represents a single equals sign. TokenTypeEquals // TokenTypeSpace represents one or more spaces or control characters. TokenTypeSpace // TokenTypeText represents a text value. This can be either a quoted-string or an unquoted value. TokenTypeText )
func (TokenType) String ¶
String implements the fmt.Stringer interface.