tor-browser

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

conditional.py (1059B)


      1 def main(request, response):
      2    tag = request.GET.first(b"tag", None)
      3    match = request.headers.get(b"If-None-Match", None)
      4    date = request.GET.first(b"date", b"")
      5    modified = request.headers.get(b"If-Modified-Since", None)
      6    cors = request.GET.first(b"cors", None)
      7 
      8    if request.method == u"OPTIONS":
      9        response.headers.set(b"Access-Control-Allow-Origin", b"*")
     10        response.headers.set(b"Access-Control-Allow-Headers", b"IF-NONE-MATCH")
     11        return b""
     12 
     13    if tag:
     14        response.headers.set(b"ETag", b'"%s"' % tag)
     15    elif date:
     16        response.headers.set(b"Last-Modified", date)
     17 
     18    if cors:
     19        response.headers.set(b"Access-Control-Allow-Origin", b"*")
     20 
     21    if ((match is not None and match == tag) or
     22            (modified is not None and modified == date)):
     23        response.status = (304, b"SUPERCOOL")
     24        return b""
     25    else:
     26        if not cors:
     27            response.headers.set(b"Access-Control-Allow-Origin", b"*")
     28        response.headers.set(b"Content-Type", b"text/plain")
     29        return b"MAYBE NOT"