tor-browser

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

wasm-helper.py (1352B)


      1 from pathlib import Path
      2 
      3 # Returns incrementer.wasm, with appropriate headers. Depending on query
      4 # parameter, it can simulate a variety of network errors.
      5 def main(request, response):
      6    error = request.GET.first(b"error", None)
      7 
      8    if error == b"close-connection":
      9        # Close connection without writing anything, to simulate a network
     10        # error. The write call is needed to avoid writing the default headers.
     11        response.writer.write("")
     12        response.close_connection = True
     13        return
     14 
     15    if error == b"http-error":
     16        response.status = (404, b"OK")
     17    else:
     18        response.status = (200, b"OK")
     19 
     20    if error == b"wrong-content-type":
     21        response.headers.set(b"Content-Type", b"application/javascript")
     22    elif error != b"no-content-type":
     23        response.headers.set(b"Content-Type", b"application/wasm")
     24 
     25    if error == b"bad-allow-fledge":
     26        response.headers.set(b"Ad-Auction-Allowed", b"sometimes")
     27    elif error == b"fledge-not-allowed":
     28        response.headers.set(b"Ad-Auction-Allowed", b"false")
     29    elif error != b"no-allow-fledge":
     30        response.headers.set(b"Ad-Auction-Allowed", b"true")
     31 
     32    if error == b"no-body":
     33        return b""
     34 
     35    if error == b"not-wasm":
     36        return b"This is not wasm"
     37 
     38    return (Path(__file__).parent.resolve() / "incrementer.wasm").read_bytes()