OLD | NEW |
| (Empty) |
1 importScripts('../../resources/get-host-info.js'); | |
2 var host_info = get_host_info(); | |
3 | |
4 self.addEventListener('install', function(event) { | |
5 event.registerForeignFetch({scopes: [registration.scope], origins: ['*']}); | |
6 }); | |
7 | |
8 self.addEventListener('foreignfetch', function(event) { | |
9 var response = JSON.parse(decodeURIComponent(location.search.substring(1))); | |
10 var url = new URL(event.request.url); | |
11 var params = JSON.parse(decodeURIComponent(url.search.substring(1))); | |
12 var url_to_fetch = 'fetch-access-control.php?'; | |
13 if (params.cross_origin) { | |
14 url_to_fetch = | |
15 host_info.HTTPS_ORIGIN + '/serviceworker/resources/' + url_to_fetch; | |
16 } | |
17 if (params.with_aceheaders) | |
18 url_to_fetch += 'ACEHeaders=X-ServiceWorker-ServerHeader&'; | |
19 if (params.with_acaorigin) | |
20 url_to_fetch += 'ACAOrigin=*'; | |
21 fetch_params = {}; | |
22 if (params.cross_origin && !params.with_acaorigin) | |
23 fetch_params.mode = 'no-cors'; | |
24 event.respondWith(fetch(url_to_fetch, fetch_params) | |
25 .then(r => { | |
26 response.response = r; | |
27 return response; | |
28 })); | |
29 return; | |
30 }); | |
OLD | NEW |