mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 11:07:54 +08:00
feat: auto add header Host
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -40,18 +40,18 @@ describe('got', () => {
|
||||
it('headers', async () => {
|
||||
nock(/rsshub\.test/)
|
||||
.get(/.*/)
|
||||
.times(4)
|
||||
.times(3)
|
||||
.reply(function() {
|
||||
expect(this.req.headers.server).toBe('RSSHub');
|
||||
expect(this.req.headers.referer).toBe('http://www.rsshub.test');
|
||||
expect(this.req.headers.referer).toBe('http://api.rsshub.test');
|
||||
expect(this.req.headers.host).toBe('api.rsshub.test');
|
||||
return [200, simpleResponse];
|
||||
});
|
||||
|
||||
await got.get('http://rsshub.test/test');
|
||||
await got.get('http://rsshub.test');
|
||||
await got.get('http://api.rsshub.test/test');
|
||||
await got.get('http://api.rsshub.test');
|
||||
|
||||
await parser.parseURL('http://rsshub.test/test');
|
||||
await parser.parseURL('http://api.rsshub.test/test');
|
||||
});
|
||||
|
||||
it('proxy socks', async () => {
|
||||
|
||||
Reference in New Issue
Block a user