MCPcopy
hub / github.com/django/django / patch_vary_headers

Function patch_vary_headers

django/utils/cache.py:300–325  ·  view source on GitHub ↗

Add (or update) the "Vary" header in the given HttpResponse object. newheaders is a list of header names that should be in "Vary". If headers contains an asterisk, then "Vary" header will consist of a single asterisk '*'. Otherwise, existing headers in "Vary" aren't removed.

(response, newheaders)

Source from the content-addressed store, hash-verified

298
299
300def patch_vary_headers(response, newheaders):
301 """
302 Add (or update) the "Vary" header in the given HttpResponse object.
303 newheaders is a list of header names that should be in "Vary". If headers
304 contains an asterisk, then "Vary" header will consist of a single asterisk
305 '*'. Otherwise, existing headers in "Vary" aren't removed.
306 """
307 # Note that we need to keep the original order intact, because cache
308 # implementations may rely on the order of the Vary contents in, say,
309 # computing an MD5 hash.
310 if response.has_header("Vary"):
311 vary_headers = cc_delim_re.split(response.headers["Vary"])
312 else:
313 vary_headers = []
314 # Use .lower() here so we treat headers as case-insensitive.
315 existing_headers = {header.lower() for header in vary_headers}
316 additional_headers = [
317 newheader
318 for newheader in newheaders
319 if newheader.lower() not in existing_headers
320 ]
321 vary_headers += additional_headers
322 if "*" in vary_headers:
323 response.headers["Vary"] = "*"
324 else:
325 response.headers["Vary"] = ", ".join(vary_headers)
326
327
328def has_vary_header(response, header_query):

Callers 8

process_responseMethod · 0.90
process_responseMethod · 0.90
_set_csrf_cookieMethod · 0.90
process_responseMethod · 0.90
_view_wrapperFunction · 0.90

Calls 3

has_headerMethod · 0.80
splitMethod · 0.45
joinMethod · 0.45