tor-browser

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

stash-headers.py (881B)


      1 import json
      2 from wptserve.utils import isomorphic_decode
      3 
      4 def main(request, response):
      5    key = request.GET[b"id"]
      6 
      7    if request.method == "POST":
      8      content_type = request.headers.get(b"content-type", b"no content-type header")
      9      ping_from = request.headers.get(b"ping-from", b"no ping-from header")
     10      ping_to = request.headers.get(b"ping-to", b"no ping-to header")
     11 
     12      value = json.dumps({
     13        'content-type': isomorphic_decode(content_type),
     14        'ping-from': isomorphic_decode(ping_from),
     15        'ping-to': isomorphic_decode(ping_to)
     16      })
     17      request.server.stash.put(key, value)
     18 
     19      return (204, [], "")
     20 
     21    elif request.method == "GET":
     22      value = request.server.stash.take(key)
     23      if value is None:
     24        value = "\"no headers yet\""
     25      return (200, [("Content-Type", "application/json")], str(value))
     26 
     27    return (405, [], "")