tor-browser

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

html-with-early-hints.h2.py (815B)


      1 def handle_headers(frame, request, response):
      2    resource_url = request.GET.first(b"resource-url").decode()
      3    link_header_value = "<{}>; rel=preload; as=script".format(resource_url)
      4    early_hints = [
      5        (b":status", b"103"),
      6        (b"link", link_header_value),
      7    ]
      8    response.writer.write_raw_header_frame(headers=early_hints,
      9                                           end_headers=True)
     10 
     11    response.status = 200
     12    response.headers[b"content-type"] = "text/html"
     13    if b"x-frame-options" in request.GET:
     14        x_frame_options = request.GET.first(b"x-frame-options").decode()
     15        response.headers[b"x-frame-options"] = x_frame_options
     16    response.write_status_headers()
     17 
     18 
     19 def main(request, response):
     20    content = "<!-- empty -->"
     21    response.writer.write_data(item=content, last=True)