normalizing query params (ref. #27)

merge-requests/23/head
Michał 'rysiek' Woźniak 2023-10-07 04:58:48 +00:00
rodzic 12d558c934
commit 428c6be365
1 zmienionych plików z 19 dodań i 1 usunięć

Wyświetl plik

@ -40,7 +40,15 @@ if (typeof self.LibResilientConfig !== 'object' || self.LibResilientConfig === n
'service-worker',
'fetch',
'cache'
]
],
// should we normalize query params?
//
// this usually makes sense: a request to example.com/?a=a&b=b is
// exactly equivalent to example.com/?b=b&a=a
//
// but in case a given website does something weird with query params...
// ..normalization can be disabled here
normalizeQueryParams: true
}
}
@ -938,6 +946,16 @@ self.addEventListener('fetch', async event => {
// clean the URL, removing any fragment identifier
var url = event.request.url.replace(/#.+$/, '');
// normalize query params, if we want that
if (self.LibResilientConfig.normalizeQueryParams) {
self.log('service-worker', 'normalizing query params')
url = url.split('?')
if (url.length > 1) {
url[1] = url[1].split('&').sort().join('&')
}
url = url.join('?')
}
// get the init object from Request
var init = initFromRequest(event.request)