Requests handled by Service Worker should not go through preflighting
[WebKit-https.git] / LayoutTests / http / tests / workers / service / resources / service-worker-crossorigin-fetch-worker.js
1 var status = "no status";
2 self.addEventListener("fetch", (event) => {
3     if (event.request.url.indexOf("status") !== -1) {
4         event.respondWith(new Response(null, {status: 200, statusText: status}));
5         return;
6     }
7     if (!event.request.url.endsWith(".fromserviceworker")) {
8         state = "unknown url";
9         event.respondWith(new Response(null, {status: 404, statusText: "Not Found"}));
10         return;
11     }
12     // Changing cors fetch into same origin fetch.
13     status = event.request.url.substring(21, event.request.url.length - 18) + " through " + "fetch";
14     event.respondWith(fetch(event.request.url.substring(21, event.request.url.length - 18)));
15 });