tor-browser

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

referrer-checker-img.py (592B)


      1 import os
      2 
      3 from wptserve.utils import isomorphic_decode
      4 
      5 # Returns a valid image response when request's |referrer| matches
      6 # |expected_referrer|.
      7 def main(request, response):
      8  referrer = request.headers.get(b"referer", b"")
      9  expected_referrer = request.GET.first(b"expected_referrer", b"")
     10  response_headers = [(b"Content-Type", b"image/png")]
     11  if referrer == expected_referrer:
     12    image_path = os.path.join(os.path.dirname(isomorphic_decode(__file__)), u"image.png")
     13    return (200, response_headers, open(image_path, mode='rb').read())
     14  return (404, response_headers, u"Not found")