summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/modules/resources/postmessage-referrer-checker.py
blob: 699af684a2366fc0aaa8c1e64abf3240489cf7be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Returns a worker script that posts the request's referrer header.
def main(request, response):
    referrer = request.headers.get(b"referer", b"")

    response_headers = [(b"Content-Type", b"text/javascript"),
                        (b"Access-Control-Allow-Origin", b"*")]

    return (200, response_headers,
            b"if ('DedicatedWorkerGlobalScope' in self &&" +
            b"    self instanceof DedicatedWorkerGlobalScope) {" +
            b"  postMessage('"+referrer+b"');" +
            b"} else if (" +
            b"    'SharedWorkerGlobalScope' in self &&" +
            b"    self instanceof SharedWorkerGlobalScope) {" +
            b"  onconnect = e => e.ports[0].postMessage('"+referrer+b"');" +
            b"}")