2015-05-13 12:56:25 +00:00
|
|
|
onfetch = function(e) {
|
2015-06-04 22:50:03 +00:00
|
|
|
if (e.request.url.indexOf("Referer") >= 0) {
|
|
|
|
// Silently rewrite the referrer so the referrer test passes since the
|
|
|
|
// document/worker isn't aware of this service worker.
|
|
|
|
var url = e.request.url.substring(0, e.request.url.indexOf('?'));
|
|
|
|
url += '?headers=' + ({ 'Referer': self.location.href }).toSource();
|
|
|
|
|
2015-09-22 21:45:25 +00:00
|
|
|
e.respondWith(e.request.text().then(function(text) {
|
|
|
|
var body = text === '' ? undefined : text;
|
|
|
|
return fetch(url, {
|
|
|
|
method: e.request.method,
|
|
|
|
headers: e.request.headers,
|
|
|
|
body: body,
|
|
|
|
mode: e.request.mode,
|
|
|
|
credentials: e.request.credentials,
|
|
|
|
redirect: e.request.redirect,
|
|
|
|
cache: e.request.cache,
|
|
|
|
});
|
2015-06-04 22:50:03 +00:00
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
2015-05-13 12:56:25 +00:00
|
|
|
e.respondWith(fetch(e.request));
|
|
|
|
};
|