update docs & test cases
This commit is contained in:
parent
58e930b4cc
commit
910cbbc170
|
|
@ -303,7 +303,29 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
|
|||
|
||||
### 代理配置
|
||||
|
||||
部分路由反爬严格,可以配置使用代理抓取
|
||||
部分路由反爬严格,可以配置使用代理抓取。
|
||||
|
||||
可通过**代理 URI**或**代理选项**两种方式来配置代理,当两种配置方式同时被设置时,RSSHub 将会使用**代理 URI**中的配置。
|
||||
|
||||
#### 代理 URI
|
||||
|
||||
`PROXY_URI`: 代理 URI,支持 socks4, socks5, http, https
|
||||
|
||||
> 代理 URI 的格式为:
|
||||
>
|
||||
> - `{protocol}://{host}:{port}`
|
||||
> - `{protocol}://{username}:{password}@{host}:{port}` (带身份凭证)
|
||||
>
|
||||
> 一些示例:
|
||||
>
|
||||
> - `socks4://127.0.0.1:1080`
|
||||
> - `socks5://user:pass@127.0.0.1:1080` (用户名为 `user`, 密码为 `pass`)
|
||||
> - `socks://127.0.0.1:1080` (protocol 为 socks 时表示 `socks5`)
|
||||
> - `http://127.0.0.1:8080`
|
||||
> - `http://user:pass@127.0.0.1:8080`
|
||||
> - `https://127.0.0.1:8443`
|
||||
|
||||
#### 代理选项
|
||||
|
||||
`PROXY_PROTOCOL`: 使用代理,支持 socks,http,https
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ let check = () => {};
|
|||
const simpleResponse = '<rss version="2.0"><channel><item></item></channel></rss>';
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env.PROXY_URI;
|
||||
delete process.env.PROXY_PROTOCOL;
|
||||
delete process.env.PROXY_HOST;
|
||||
delete process.env.PROXY_PORT;
|
||||
|
|
@ -54,6 +55,67 @@ describe('got', () => {
|
|||
await parser.parseURL('http://api.rsshub.test/test');
|
||||
});
|
||||
|
||||
it('proxy-uri socks', async () => {
|
||||
process.env.PROXY_URI = 'socks5://user:pass@rsshub.proxy:2333';
|
||||
|
||||
jest.resetModules();
|
||||
require('../../lib/utils/request-wrapper');
|
||||
check = (request) => {
|
||||
expect(request.agent.constructor.name).toBe('SocksProxyAgent');
|
||||
expect(request.agent.proxy.host).toBe('rsshub.proxy');
|
||||
expect(request.agent.proxy.port).toBe(2333);
|
||||
};
|
||||
|
||||
nock(/rsshub\.test/)
|
||||
.get('/proxy')
|
||||
.times(2)
|
||||
.reply(200, simpleResponse);
|
||||
|
||||
await got.get('http://rsshub.test/proxy');
|
||||
await parser.parseURL('http://rsshub.test/proxy');
|
||||
});
|
||||
|
||||
it('proxy-uri http', async () => {
|
||||
process.env.PROXY_URI = 'http://user:pass@rsshub.proxy:2333';
|
||||
|
||||
jest.resetModules();
|
||||
require('../../lib/utils/request-wrapper');
|
||||
check = (request) => {
|
||||
expect(request.agent.constructor.name).toBe('HttpsProxyAgent');
|
||||
expect(request.agent.proxy.auth).toBe('user:pass');
|
||||
expect(request.agent.proxy.host).toBe('rsshub.proxy');
|
||||
expect(request.agent.proxy.port).toBe(2333);
|
||||
};
|
||||
|
||||
nock(/rsshub\.test/)
|
||||
.get('/proxy')
|
||||
.times(2)
|
||||
.reply(200, simpleResponse);
|
||||
|
||||
await got.get('http://rsshub.test/proxy');
|
||||
await parser.parseURL('http://rsshub.test/proxy');
|
||||
});
|
||||
|
||||
it('proxy-uri https', async () => {
|
||||
process.env.PROXY_URI = 'https://rsshub.proxy:2333';
|
||||
|
||||
jest.resetModules();
|
||||
require('../../lib/utils/request-wrapper');
|
||||
check = (request) => {
|
||||
expect(request.agent.constructor.name).toBe('HttpsProxyAgent');
|
||||
expect(request.agent.proxy.host).toBe('rsshub.proxy');
|
||||
expect(request.agent.proxy.port).toBe(2333);
|
||||
};
|
||||
|
||||
nock(/rsshub\.test/)
|
||||
.get('/proxy')
|
||||
.times(2)
|
||||
.reply(200, simpleResponse);
|
||||
|
||||
await got.get('http://rsshub.test/proxy');
|
||||
await parser.parseURL('http://rsshub.test/proxy');
|
||||
});
|
||||
|
||||
it('proxy socks', async () => {
|
||||
process.env.PROXY_PROTOCOL = 'socks';
|
||||
process.env.PROXY_HOST = 'rsshub.proxy';
|
||||
|
|
|
|||
Loading…
Reference in New Issue