summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/browsing-topics/resources/check-topics-request-header-notify-parent.py
blob: 98c77c2b0bd21591416d886d1ab013486a805550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def main(request, response):
    """
    Returns an HTML response that notifies its parent frame the topics header
    via postMessage
    """

    topics_header = request.headers.get(b"sec-browsing-topics", b"NO_TOPICS_HEADER")

    headers = [(b"Content-Type", b"text/html"),
               (b"Access-Control-Allow-Origin", b"*")]
    content = b'''
<script>
  let parentOrOpener = window.opener || window.parent;
  parentOrOpener.postMessage({ topicsHeader: '%s'}, "*");
</script>
''' % (topics_header)

    return 200, headers, content