зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1217501 P3 Check Accept header visibility in service worker fetch event. r=ehsan
This commit is contained in:
Родитель
ac1df23ecf
Коммит
daae12696c
|
@ -23,7 +23,7 @@
|
|||
|
||||
// Resolve a promise when we recieve 2 success messages
|
||||
return new Promise(function(resolve, reject) {
|
||||
var remaining = 2;
|
||||
var remaining = 4;
|
||||
function onMessage(e) {
|
||||
if (e.data == 'PASS') {
|
||||
remaining--;
|
||||
|
|
|
@ -32,4 +32,35 @@
|
|||
}).catch(function(err) {
|
||||
parent.postMessage('noUA FAIL - unexpected error: ' + err, '*');
|
||||
});
|
||||
|
||||
var uri = document.location + '?check-accept-header';
|
||||
var headers = new Headers();
|
||||
headers.set('Accept', 'hmm');
|
||||
|
||||
// Check for custom accept header
|
||||
fetch(uri, { headers: headers }).then(function(response) {
|
||||
return response.text();
|
||||
}).then(function(text) {
|
||||
if (text === headers.get('Accept')) {
|
||||
parent.postMessage('PASS', '*');
|
||||
} else {
|
||||
parent.postMessage('custom accept FAIL - expected ' + headers.get('Accept') +
|
||||
' got "' + text + '"', '*');
|
||||
}
|
||||
}).catch(function(err) {
|
||||
parent.postMessage('custom accept FAIL - unexpected error: ' + err, '*');
|
||||
});
|
||||
|
||||
// Check for default accept header
|
||||
fetch(uri).then(function(response) {
|
||||
return response.text();
|
||||
}).then(function(text) {
|
||||
if (text === '*/*') {
|
||||
parent.postMessage('PASS', '*');
|
||||
} else {
|
||||
parent.postMessage('accept FAIL - expected */* got "' + text + '"', '*');
|
||||
}
|
||||
}).catch(function(err) {
|
||||
parent.postMessage('accept FAIL - unexpected error: ' + err, '*');
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -63,6 +63,14 @@ self.addEventListener('fetch', function(event) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (params['check-accept-header']) {
|
||||
var accept = event.request.headers.get('Accept');
|
||||
if (accept) {
|
||||
event.respondWith(new Response(accept));
|
||||
} else {
|
||||
event.respondWith(new Response('NO_ACCEPT'));
|
||||
}
|
||||
}
|
||||
event.respondWith(new Promise(function(resolve, reject) {
|
||||
var request = event.request;
|
||||
if (url) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче