-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify original response by prevent-fetch. AG-20293 #297
Squashed commit of the following: commit 5fb4979 Author: Slava Leleka <v.leleka@adguard.com> Date: Thu May 11 18:46:34 2023 +0300 use await instead of then commit 4c4046c Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 20:42:44 2023 +0300 mark startsWith() and endsWith() helpers as deprecated commit c21eccc Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 20:37:37 2023 +0300 improve responseType checking condition commit 68f3b60 Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 20:33:10 2023 +0300 fix INPUT_JSON_PATH commit 087f934 Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 20:32:36 2023 +0300 fix assert.async() commit dc62a81 Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 15:14:13 2023 +0300 fix imports commit 4423117 Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 14:44:36 2023 +0300 Revert "update babel/runtime" This reverts commit abab623. commit bb234c4 Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 14:42:45 2023 +0300 improve invalid param error text commit a1bd1da Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 14:36:00 2023 +0300 update changelog commit 5e4e47c Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 14:35:08 2023 +0300 update changelog commit 531ea12 Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 14:19:55 2023 +0300 modify original response by prevent-fetch commit abab623 Author: Slava Leleka <v.leleka@adguard.com> Date: Wed May 10 14:16:37 2023 +0300 update babel/runtime
- Loading branch information
1 parent
e60fdd1
commit e7295bd
Showing
6 changed files
with
199 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Modifies original response with the given replacement data. | ||
* | ||
* @param {Response} origResponse Original response. | ||
* @param {Object} replacement Replacement data for response with possible keys: | ||
* - `body`: optional, string, default to '{}'; | ||
* - `type`: optional, string, original response type is used if not specified. | ||
* | ||
* @returns {Response} Modified response. | ||
*/ | ||
export const modifyResponse = ( | ||
origResponse, | ||
replacement = { | ||
body: '{}', | ||
}, | ||
) => { | ||
const headers = {}; | ||
origResponse?.headers?.forEach((value, key) => { | ||
headers[key] = value; | ||
}); | ||
|
||
const modifiedResponse = new Response(replacement.body, { | ||
status: origResponse.status, | ||
statusText: origResponse.statusText, | ||
headers, | ||
}); | ||
|
||
// Mock response url and type to avoid adblocker detection | ||
// https://github.com/AdguardTeam/Scriptlets/issues/216 | ||
Object.defineProperties(modifiedResponse, { | ||
url: { | ||
value: origResponse.url, | ||
}, | ||
type: { | ||
value: replacement.type || origResponse.type, | ||
}, | ||
}); | ||
|
||
return modifiedResponse; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.