feat: auto add header Host

This commit is contained in:
DIYgod
2020-02-15 21:32:16 +08:00
parent befd42d2a8
commit 48b27fe811
2 changed files with 11 additions and 13 deletions

View File

@@ -86,14 +86,12 @@ const requestWrapper = (url, options) => {
// referer
if (!options.headers.referer && !options.headers.Referer) {
const protocol = url.match('https?://');
url = url.replace(/(https?:)?\/\//, '');
const domain = url
.split('.')
.slice(-2)
.join('.')
.split('/')[0];
options.headers.referer = (protocol ? protocol[0] : 'https://') + 'www.' + domain;
const urlHandler = new URL(url);
options.headers.referer = urlHandler.origin;
}
if (!options.headers.host && !options.headers.Host) {
const urlHandler = new URL(url);
options.headers.host = urlHandler.host;
}
};