mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-09 12:22:33 +01:00
Improve prevent-fetch
scriptlet
Add `statusText` as overridable property in response instance. Supported values are: `""`, `"Not Found"`. `statusText` defaults to `"OK"` when not overridden.
This commit is contained in:
parent
324102cb65
commit
9ce3056361
@ -2089,11 +2089,13 @@ function noFetchIf(
|
||||
}
|
||||
const validResponseProps = {
|
||||
ok: [ false, true ],
|
||||
type: [ 'basic', 'cors', 'opaque' ],
|
||||
statusText: [ '', 'Not Found' ],
|
||||
type: [ 'basic', 'cors', 'default', 'error', 'opaque' ],
|
||||
};
|
||||
const responseProps = {
|
||||
statusText: { value: 'OK' },
|
||||
};
|
||||
let responseProps;
|
||||
if ( /^\{.*\}$/.test(responseType) ) {
|
||||
responseProps = {};
|
||||
try {
|
||||
Object.entries(JSON.parse(responseType)).forEach(([ p, v ]) => {
|
||||
if ( validResponseProps[p] === undefined ) { return; }
|
||||
@ -2104,7 +2106,7 @@ function noFetchIf(
|
||||
catch(ex) {}
|
||||
} else if ( responseType !== '' ) {
|
||||
if ( validResponseProps.type.includes(responseType) ) {
|
||||
responseProps = { type: { value: responseType } };
|
||||
responseProps.type = { value: responseType };
|
||||
}
|
||||
}
|
||||
self.fetch = new Proxy(self.fetch, {
|
||||
@ -2147,7 +2149,6 @@ function noFetchIf(
|
||||
return generateContentFn(responseBody).then(text => {
|
||||
safe.uboLog(logPrefix, `Prevented with response "${text}"`);
|
||||
const response = new Response(text, {
|
||||
statusText: 'OK',
|
||||
headers: {
|
||||
'Content-Length': text.length,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user