bytecheck-worker.py (1166B)
1 import time 2 3 def main(request, response): 4 headers = [(b'Content-Type', b'application/javascript'), 5 (b'Cache-Control', b'max-age=0')] 6 7 main_content_type = b'' 8 if b'main' in request.GET: 9 main_content_type = request.GET[b'main'] 10 11 main_content = b'default' 12 if main_content_type == b'time': 13 main_content = b'%f' % time.time() 14 15 imported_request_path = b'' 16 if b'path' in request.GET: 17 imported_request_path = request.GET[b'path'] 18 19 imported_request_type = b'' 20 if b'imported' in request.GET: 21 imported_request_type = request.GET[b'imported'] 22 23 imported_request = b'' 24 if imported_request_type == b'time': 25 imported_request = b'?imported=time' 26 27 if b'type' in request.GET and request.GET[b'type'] == b'module': 28 body = b''' 29 // %s 30 import '%sbytecheck-worker-imported-script.py%s'; 31 ''' % (main_content, imported_request_path, imported_request) 32 else: 33 body = b''' 34 // %s 35 importScripts('%sbytecheck-worker-imported-script.py%s'); 36 ''' % (main_content, imported_request_path, imported_request) 37 38 return headers, body