kopia lustrzana https://gitlab.com/rysiekpl/libresilient
normalizing query params (ref. #27)
rodzic
12d558c934
commit
428c6be365
|
@ -40,7 +40,15 @@ if (typeof self.LibResilientConfig !== 'object' || self.LibResilientConfig === n
|
||||||
'service-worker',
|
'service-worker',
|
||||||
'fetch',
|
'fetch',
|
||||||
'cache'
|
'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
|
// clean the URL, removing any fragment identifier
|
||||||
var url = event.request.url.replace(/#.+$/, '');
|
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
|
// get the init object from Request
|
||||||
var init = initFromRequest(event.request)
|
var init = initFromRequest(event.request)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue