tor-browser

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

set-cookie.py (952B)


      1 from datetime import date
      2 
      3 def main(request, response):
      4    """
      5    Returns cookie name and path from query params in a Set-Cookie header.
      6 
      7    e.g.
      8 
      9    > GET /cookies/resources/set-cookie.py?name=match-slash&path=%2F HTTP/1.1
     10    > Host: localhost:8000
     11    > User-Agent: curl/7.43.0
     12    > Accept: */*
     13    >
     14    < HTTP/1.1 200 OK
     15    < Content-Type: application/json
     16    < Set-Cookie: match-slash=1; Path=/; Expires=09 Jun 2021 10:18:14 GMT
     17    < Server: BaseHTTP/0.3 Python/2.7.12
     18    < Date: Tue, 04 Oct 2016 18:16:06 GMT
     19    < Content-Length: 80
     20    """
     21 
     22    name = request.GET[b'name']
     23    path = request.GET[b'path']
     24    value = request.GET.first(b'value', b"1")
     25    expiry_year = date.today().year + 1
     26    cookie = b"%s=%s; Path=%s; Expires=09 Jun %d 10:18:14 GMT" % (name, value, path, expiry_year)
     27 
     28    headers = [
     29        (b"Content-Type", b"application/json"),
     30        (b"Set-Cookie", cookie)
     31    ]
     32    body = b"{}"
     33    return headers, body