tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

vary.py (1039B)


      1 def main(request, response):
      2  if b"clear-vary-value-override-cookie" in request.GET:
      3    response.unset_cookie(b"vary-value-override")
      4    return b"vary cookie cleared"
      5 
      6  set_cookie_vary = request.GET.first(b"set-vary-value-override-cookie",
      7                                      default=b"")
      8  if set_cookie_vary:
      9    response.set_cookie(b"vary-value-override", set_cookie_vary)
     10    return b"vary cookie set"
     11 
     12  # If there is a vary-value-override cookie set, then use its value
     13  # for the VARY header no matter what the query string is set to.  This
     14  # override is necessary to test the case when two URLs are identical
     15  # (including query), but differ by VARY header.
     16  cookie_vary = request.cookies.get(b"vary-value-override")
     17  if cookie_vary:
     18    response.headers.set(b"vary", str(cookie_vary))
     19  else:
     20    # If there is no cookie, then use the query string value, if present.
     21    query_vary = request.GET.first(b"vary", default=b"")
     22    if query_vary:
     23      response.headers.set(b"vary", query_vary)
     24 
     25  return b"vary response"