MCPcopy Create free account
hub / github.com/psf/cachecontrol / BaseHeuristic

Class BaseHeuristic

cachecontrol/heuristics.py:27–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26
27class BaseHeuristic:
28 def warning(self, response: HTTPResponse) -> str | None:
29 """
30 Return a valid 1xx warning header value describing the cache
31 adjustments.
32
33 The response is provided too allow warnings like 113
34 http://tools.ietf.org/html/rfc7234#section-5.5.4 where we need
35 to explicitly say response is over 24 hours old.
36 """
37 return '110 - "Response is Stale"'
38
39 def update_headers(self, response: HTTPResponse) -> dict[str, str]:
40 """Update the response headers with any new headers.
41
42 NOTE: This SHOULD always include some Warning header to
43 signify that the response was cached by the client, not
44 by way of the provided headers.
45 """
46 return {}
47
48 def apply(self, response: HTTPResponse) -> HTTPResponse:
49 updated_headers = self.update_headers(response)
50
51 if updated_headers:
52 response.headers.update(updated_headers)
53 warning_header_value = self.warning(response)
54 if warning_header_value is not None:
55 response.headers.update({"Warning": warning_header_value})
56
57 return response
58
59
60class OneDayCache(BaseHeuristic):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…