-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to set
Referer
header on downloads
- Loading branch information
Showing
11 changed files
with
103 additions
and
5 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
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
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,51 @@ | ||
const Headers = { | ||
refererListener: details => { | ||
// TODO: option to ignore or rewrite referer, check if needed | ||
const existingReferer = details.requestHeaders.find( | ||
h => h.name === "Referer" | ||
); | ||
if (existingReferer) { | ||
return {}; | ||
} | ||
|
||
if (!globalChromeState || !globalChromeState.info) { | ||
return {}; | ||
} | ||
|
||
const { pageUrl } = globalChromeState.info; | ||
if (!pageUrl) { | ||
return {}; | ||
} | ||
|
||
const referer = { | ||
name: "Referer", | ||
value: pageUrl | ||
}; | ||
details.requestHeaders.push(referer); | ||
|
||
return { requestHeaders: details.requestHeaders }; | ||
}, | ||
|
||
addRequestListener: () => { | ||
browser.webRequest.onBeforeSendHeaders.removeListener( | ||
Headers.refererListener | ||
); | ||
|
||
if (options.setRefererHeader) { | ||
const filterList = options.setRefererHeaderFilter || ""; | ||
|
||
const urls = filterList.split("\n").map(s => s.trim()); | ||
|
||
browser.webRequest.onBeforeSendHeaders.addListener( | ||
Headers.refererListener, | ||
{ urls }, | ||
["blocking", "requestHeaders"] | ||
); | ||
} | ||
} | ||
}; | ||
|
||
// Export for testing | ||
if (typeof module !== "undefined") { | ||
module.exports = Headers; | ||
} |
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