harp.http.utils.cache

parse_cache_control(value)[source]

Parse a Cache-Control header from either a request or response.

This is the main entry point for parsing.

Args:

value: The Cache-Control header value

Returns:

CacheControl object containing all parsed directives

Examples:
>>> # Response example
>>> cc = parse_cache_control("public, max-age=3600, must-revalidate")
>>> cc.public
True
>>> cc.max_age
3600
>>> cc.must_revalidate
True
>>> # Request example
>>> cc = parse_cache_control("max-age=0, no-cache")
>>> cc.max_age
0
>>> cc.no_cache
True
>>> # With field names
>>> cc = parse_cache_control('no-cache="Set-Cookie, Authorization"')
>>> cc.no_cache
['Set-Cookie', 'Authorization']
>>> # Experimental directives
>>> cc = parse_cache_control("immutable, stale-while-revalidate=86400")
>>> cc.immutable
True
>>> cc.stale_while_revalidate
86400
Parameters:

value (str | None)

Return type:

CacheControl