summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/storage-access-api/resources/embedded_worker.py
blob: 0aa457657f1f571a5d9ac2d197e77801476b73ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from cookies.resources.helpers import setNoCacheAndCORSHeaders

# This worker messages how many connections have been made and checks what cookies are available.
def main(request, response):
    headers = setNoCacheAndCORSHeaders(request, response)
    headers[0] = (b"Content-Type", b"text/javascript")
    cookie_header = request.headers.get(b"Cookie", b"")
    document = b"""
"use strict";

self.onmessage = async (message) => {
  function reply(data) {
    self.postMessage({data});
  }

  switch (message.data.command) {
    case "fetch": {
      const response = await fetch(message.data.url, {mode: 'cors', credentials: 'include'})
        .then((resp) => resp.text());
      reply(response);
      break;
    }
    case "load": {
      reply(\"""" + cookie_header + b"""");
      break;
    }
    default:
  }
};
"""
    return headers, document