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)
| 298 | |
| 299 | |
| 300 | def 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 | |
| 328 | def has_vary_header(response, header_query): |