tor-browser

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

2x3-svg-scaled-by-sec-ch-width.py (733B)


      1 def main(request, response):
      2    """
      3    Simple handler that responds with an SVG image with width `2 * sec-ch-width`
      4    and height `3 * sec-ch-width`, or 1x1 if sec-ch-width is not present.
      5    """
      6 
      7    width = 1
      8    height = 1
      9 
     10    if b"sec-ch-width" in request.headers:
     11      sec_ch_width = request.headers.get(b"sec-ch-width").decode()
     12      width = 2 * int(sec_ch_width)
     13      height = 3 * int(sec_ch_width)
     14 
     15    response.headers.set(b"Content-Type", b"image/svg+xml")
     16    response.content = str.encode(f"""<svg
     17        xmlns="http://www.w3.org/2000/svg"
     18        xmlns:xlink="http://www.w3.org/1999/xlink"
     19        width="{width}"
     20        height="{height}">
     21      <rect width="100%" height="100%" fill="green" />
     22    </svg>""")