| 25 | |
| 26 | |
| 27 | class 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 | |
| 60 | class OneDayCache(BaseHeuristic): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…