instagram在使用IG_PROXY时访问失败,溯源发现是utils\request-rewriter\get.ts用options还原url的处理有bug
- Dominant language
- TypeScript
- Stars
- 46.2k
- Forks
- 10.2k
- Avg merge
- 8h 48m
- Merged PRs (30d)
- 175
Description
### 路由地址
```routes
/instagram/:category/:key
```
### 完整路由地址
```fullroutes
/instagram/user/stefaniejoosten
```
### 相关文档
https://docs.rsshub.app/zh/routes/social-media#instagram
### 预期是什么?
正常访问获取结果
### 实际发生了什么?
访问时报错
```
info: <-- GET /instagram/user/stefaniejoosten
debug: Outgoing request: POST https://i.instagram.com/api/v1/qe/sync/
debug: Outgoing request: CONNECT http://127.0.0.1i.instagram.com:443/
error: Error in /instagram/user/stefaniejoosten: RequestError: RequestError: Error: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 127.0.0.1i.instagram.com
at Request.faultTolerantRequest (E:\Coding\RSSHub-240902\node_modules\.pnpm\instagram-private-api@1.46.1\node_modules\instagram-private-api\src\core\request.ts:179:13)
at async Request.send (E:\Coding\RSSHub-240902\node_modules\.pnpm\instagram-private-api@1.46.1\node_modules\instagram-private-api\src\core\request.ts:77:22)
```
### 部署
自建
### 部署相关信息
OS: Ubuntu, Node: v22.9.0
### 额外信息
- 配置了 `IG_USERNAME`、`IG_PASSWORD`,以及`IG_PROXY=http://127.0.0.1:10809`,因此使用的是`instagram-private-api`。
- `instagram-private-api`使用`request-promise`库发送http请求。追溯到[request库的文档](https://github.com/request/request#proxies)发现,配置代理后,访问`https`网址会先给代理发送一个`CONNECT`,如:
```
HTTP/1.1 CONNECT endpoint-server.com:80
Host: proxy-server.com
User-Agent: whatever user agent you specify
```
代理返回200后,进行后续请求(具体的我就不太懂了,详见他们的文档说明)。
- `request`库的请求好像是被`utils\request-rewriter\get.ts`拦截了,上述给代理发送的`CONNECT`请求走的是[`options = args[0];`](https://github.com/DIYgod/RSSHub/blob/8ec92353447858adcc2b0079a20111ae48cdf26c/lib/utils/request-rewriter/get.ts#L26)的分支,对应构造的`url`为
```
url = new URL(options.href || `${options.protocol || 'http:'}//${options.hostname || options.host}${options.path}${options.search || (options.query ? `?${options.query}` : '')}`);
```
我这里log出的`options`内容为:
```json
{
"host": "127.0.0.1",
"port": 10809,
"proxyAuth": null,
"headers": {
"User-Agent": "...",
"Accept-Language": "en-US",
"Accept-Encoding": "gzip",
"Connection": "close",
"host": "i.instagram.com:443"
},
"method": "CONNECT",
"path": "i.instagram.com:443",
"agent": false
}
```
由此构造了错误的`url`: `http://127.0.0.1i.instagram.com:443/`,导致报错。
但我不知道正确解法,所以把发现的问题贴上来讨论。
### 这不是重复的 issue
- [X] 我已经搜索了 [现有 issue](https://github.com/DIYgod/RSSHub/issues),以确保该错误尚未被报告。
Contributor guide
Assessment
This issue has not been assessed yet.