tor-browser

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

coep-mismatch.h2.py (1130B)


      1 import os
      2 
      3 
      4 def handle_headers(frame, request, response):
      5    # Send a 103 response.
      6    resource_url = request.GET.first(b"resource-url").decode()
      7    link_header_value = "<{}>; rel=preload; as=script".format(resource_url)
      8    coep_value = request.GET.first(b"early-hints-policy").decode()
      9    early_hints = [
     10        (b":status", b"103"),
     11        (b"cross-origin-embedder-policy", coep_value),
     12        (b"link", link_header_value),
     13    ]
     14    response.writer.write_raw_header_frame(headers=early_hints,
     15                                           end_headers=True)
     16 
     17    # Send the final response header.
     18    coep_value = request.GET.first(b"final-policy").decode()
     19    response.status = 200
     20    response.headers["content-type"] = "text/html"
     21    response.headers["cross-origin-embedder-policy"] = coep_value
     22    response.write_status_headers()
     23 
     24 
     25 def main(request, response):
     26    current_dir = os.path.dirname(os.path.realpath(__file__))
     27    file_path = os.path.join(current_dir, "coep-mismatch.html")
     28    with open(file_path, "r") as f:
     29        test_content = f.read()
     30    response.writer.write_data(item=test_content, last=True)