tor-browser

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

arbitrary-header-in-early-hints.h2.py (801B)


      1 import os
      2 
      3 
      4 def handle_headers(frame, request, response):
      5    # Send an early hints response with an unsupported header.
      6    # User agents should ignore it.
      7    early_hints = [
      8        (b":status", b"103"),
      9        (b"x-arbitrary-header", b"foobar"),
     10    ]
     11    response.writer.write_raw_header_frame(headers=early_hints,
     12                                           end_headers=True)
     13 
     14    response.status = 200
     15    response.headers[b"content-type"] = "text/html"
     16    response.write_status_headers()
     17 
     18 
     19 def main(request, response):
     20    current_dir = os.path.dirname(os.path.realpath(__file__))
     21    file_path = os.path.join(current_dir, "arbitrary-header-in-early-hints.html")
     22    with open(file_path, "r") as f:
     23        test_content = f.read()
     24    response.writer.write_data(item=test_content, last=True)