echo-referrer.py (642B)
1 """A page that echoes the Referrer header value via BroadcastChannel. 2 """ 3 4 5 def main(request, response): 6 referrer = request.headers.get(b"referer") 7 uid = request.GET.first(b"uid") 8 9 if referrer is None: 10 referrer = b"(none)" 11 12 html = u''' 13 <html> 14 <head> 15 <title>Echo referrer</title> 16 </head> 17 <script src="/speculation-rules/prerender/resources/utils.js"></script> 18 <body> 19 <script> 20 const bc = new PrerenderChannel('prerender-channel', '%s'); 21 bc.postMessage({referrer: '%s'}); 22 </script> 23 </body> 24 </html> 25 ''' 26 return (200, [("Content-Type", b"text/html")], 27 html % (uid.decode("utf-8"), referrer.decode("utf-8")))