MCPcopy
hub / github.com/django/django / patch_response_headers

Function patch_response_headers

django/utils/cache.py:271–287  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

269
270
271def 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
290def add_never_cache_headers(response):

Callers 2

process_responseMethod · 0.90
add_never_cache_headersFunction · 0.85

Calls 4

http_dateFunction · 0.90
patch_cache_controlFunction · 0.85
has_headerMethod · 0.80
timeMethod · 0.80

Tested by

no test coverage detected