Skip to content

Commit cabcd96

Browse files
authored
feat: make the tester anonymity-check URL configurable via TEST_ANONYMOUS_URL (#234)
- setting: add TEST_ANONYMOUS_URL (default https://httpbin.org/ip) - tester: use TEST_ANONYMOUS_URL instead of the hardcoded httpbin.org endpoint so users can self-host httpbin and avoid public rate limits - README: document TEST_ANONYMOUS_URL and TEST_ANONYMOUS Closes #109
1 parent b915026 commit cabcd96

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ GET http://localhost:5555/all?area=CN
277277
- TEST_TIMEOUT:测试超时时间,默认 10 秒
278278
- TEST_BATCH:批量测试数量,默认 20 个代理
279279
- TEST_VALID_STATUS:测试有效的状态码
280+
- TEST_ANONYMOUS:是否只保留匿名代理,默认 true
281+
- TEST_ANONYMOUS_URL:匿名 / 出口 IP 检测地址,默认 `https://httpbin.org/ip`,需返回 httpbin 格式的 JSON(`{"origin": "1.2.3.4"}`)。可指向自建 httpbin 服务以避免公共服务限流
280282
- API_HOST:代理 Server 运行 Host,默认 0.0.0.0
281283
- API_PORT:代理 Server 运行端口,默认 5555
282284
- API_THREADED:代理 Server 是否使用多线程,默认 true

proxypool/processors/tester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from proxypool.schemas import Proxy
55
from proxypool.storages.redis import RedisClient
66
from proxypool.setting import TEST_TIMEOUT, TEST_BATCH, TEST_URL, TEST_VALID_STATUS, TEST_ANONYMOUS, \
7-
TEST_DONT_SET_MAX_SCORE
7+
TEST_DONT_SET_MAX_SCORE, TEST_ANONYMOUS_URL
88
from aiohttp import ClientProxyConnectionError, ServerDisconnectedError, ClientOSError, ClientHttpProxyError, \
99
ClientResponseError, ContentTypeError
1010
from asyncio import TimeoutError
@@ -49,7 +49,7 @@ async def test(self, proxy: Proxy, session: aiohttp.ClientSession):
4949
# the proxy has the effect of hiding the real IP
5050
# logger.debug(f'TEST_ANONYMOUS {TEST_ANONYMOUS}')
5151
if TEST_ANONYMOUS:
52-
url = 'https://httpbin.org/ip'
52+
url = TEST_ANONYMOUS_URL
5353
async with session.get(url, timeout=TEST_TIMEOUT) as response:
5454
resp_json = await response.json()
5555
origin_ip = resp_json['origin']

proxypool/setting.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
TEST_BATCH = env.int('TEST_BATCH', 20)
7676
# only save anonymous proxy
7777
TEST_ANONYMOUS = env.bool('TEST_ANONYMOUS', True)
78+
# the url used to check the proxy anonymity and its exit ip;
79+
# must return json like httpbin.org/ip ({"origin": "1.2.3.4"});
80+
# point this to a self-hosted httpbin to avoid public rate limits
81+
TEST_ANONYMOUS_URL = env.str('TEST_ANONYMOUS_URL', 'https://httpbin.org/ip')
7882
# TEST_HEADERS = env.json('TEST_HEADERS', {
7983
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36',
8084
# })

0 commit comments

Comments
 (0)