Add HTTP caching headers to the given HttpResponse: Expires and Cache-Control. Each header is only added if it isn't already set. cache_timeout is in seconds. The CACHE_MIDDLEWARE_SECONDS setting is used by default.
(response, cache_timeout=None)
| 269 | |
| 270 | |
| 271 | def patch_response_headers(response, cache_timeout=None): |
| 272 | """ |
| 273 | Add HTTP caching headers to the given HttpResponse: Expires and |
| 274 | Cache-Control. |
| 275 | |
| 276 | Each header is only added if it isn't already set. |
| 277 | |
| 278 | cache_timeout is in seconds. The CACHE_MIDDLEWARE_SECONDS setting is used |
| 279 | by default. |
| 280 | """ |
| 281 | if cache_timeout is None: |
| 282 | cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS |
| 283 | if cache_timeout < 0: |
| 284 | cache_timeout = 0 # Can't have max-age negative |
| 285 | if not response.has_header("Expires"): |
| 286 | response.headers["Expires"] = http_date(time.time() + cache_timeout) |
| 287 | patch_cache_control(response, max_age=cache_timeout) |
| 288 | |
| 289 | |
| 290 | def add_never_cache_headers(response): |
no test coverage detected