summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resources/bytecheck-worker.py
blob: 10f3bceb4fd6c1375afaa362143c5d403dec94d8 (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
32
33
34
35
36
37
38
import time

def main(request, response):
    headers = [(b'Content-Type', b'application/javascript'),
               (b'Cache-Control', b'max-age=0')]

    main_content_type = b''
    if b'main' in request.GET:
        main_content_type = request.GET[b'main']

    main_content = b'default'
    if main_content_type == b'time':
        main_content = b'%f' % time.time()

    imported_request_path = b''
    if b'path' in request.GET:
        imported_request_path = request.GET[b'path']

    imported_request_type = b''
    if b'imported' in request.GET:
        imported_request_type = request.GET[b'imported']

    imported_request = b''
    if imported_request_type == b'time':
        imported_request = b'?imported=time'

    if b'type' in request.GET and request.GET[b'type'] == b'module':
        body = b'''
        // %s
        import '%sbytecheck-worker-imported-script.py%s';
        ''' % (main_content, imported_request_path, imported_request)
    else:
        body = b'''
        // %s
        importScripts('%sbytecheck-worker-imported-script.py%s');
        ''' % (main_content, imported_request_path, imported_request)

    return headers, body