tor-browser

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

report.py (917B)


      1 def main(request, response):
      2 
      3    # `token` should be a unique UUID request parameter for the duration of this
      4    # request. It will get stored in the server stash and will be used later in
      5    # a query request.
      6    # `query` should be a request parameter indicating the request would like
      7    # to know how many times the server has seen the request (with the
      8    # same token).
      9    token = request.GET.first(b"token", None)
     10    is_query = request.GET.first(b"query", None) is not None
     11    with request.server.stash.lock:
     12        value = request.server.stash.take(token)
     13        count = 0
     14        if value is not None:
     15            count = int(value)
     16        if is_query:
     17            request.server.stash.put(token, count)
     18        else:
     19            count += 1
     20            request.server.stash.put(token, count)
     21 
     22    headers = []
     23    if is_query:
     24        headers = [(b"Count", count)]
     25    return (200, headers, b"")