tor-browser

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

huge-response.py (683B)


      1 # A Python script that generates a huge response. Implemented as a script to
      2 # avoid needing to add a huge file to the repository.
      3 
      4 TOTAL_SIZE = 8 * 1024 * 1024 * 1024  # 8 GB
      5 CHUNK_SIZE = 1024 * 1024  # 1 MB
      6 
      7 assert TOTAL_SIZE % CHUNK_SIZE == 0
      8 
      9 
     10 def main(request, response):
     11    response.headers.set(b"Content-type", b"text/plain")
     12    response.headers.set(b"Content-Length", str(TOTAL_SIZE).encode())
     13    response.headers.set(b"Cache-Control", b"max-age=86400")
     14    response.write_status_headers()
     15 
     16    chunk = bytes(CHUNK_SIZE)
     17    total_sent = 0
     18 
     19    while total_sent < TOTAL_SIZE:
     20        if not response.writer.write(chunk):
     21            break
     22        total_sent += CHUNK_SIZE