feat: bypass reverse proxy for requests with cookies

This commit is contained in:
DIYgod 2023-07-23 21:28:00 +01:00
parent d7224338a5
commit cd6b5e0f0b
No known key found for this signature in database
3 changed files with 16 additions and 2 deletions

View File

@ -565,6 +565,12 @@ resolved by the SOCKS server, recommanded, prevents DNS poisoning or DNS leak),
### Reverse proxy
::: warning
This proxy method cannot proxy requests that contain cookies.
:::
`REVERSE_PROXY_URL`: Reverse proxy URL, RSSHub will use this URL as a prefix to initiate requests, for example `https://proxy.example.com?target=`, requests to `https://google.com` will be automatically converted to `https://proxy.example.com?target=https%3A%2F%2Fgoogle.com`
You can use Cloudflare Workers to build a simple reverse proxy, for example:

View File

@ -585,6 +585,12 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
### 反向代理
::: warning 注意
这种代理方式无法代理包含 cookie 的请求。
:::
`REVERSE_PROXY_URL`: 反向代理地址RSSHub 将会使用该地址作为前缀来发起请求,例如 `https://proxy.example.com/?target=`,对 `https://google.com` 发起的请求将被自动转换为 `https://proxy.example.com/?target=https%3A%2F%2Fgoogle.com`
你可以使用 Cloudflare Workers 来搭建一个简易的反向代理,例如:

View File

@ -40,8 +40,10 @@ if (agent) {
};
} else if (config.reverseProxyUrl) {
proxyWrapper = (url, options) => {
if (!((options.url || url) + '').startsWith(config.reverseProxyUrl)) {
options.url = new URL(`${config.reverseProxyUrl}${encodeURIComponent(options.url || url)}`);
const urlIn = options.url.toString() || url;
const proxyRegex = new RegExp(proxyObj.url_regex);
if (proxyRegex.test(urlIn) && !urlIn.startsWith(config.reverseProxyUrl) && !options.cookieJar) {
options.url = new URL(`${config.reverseProxyUrl}${encodeURIComponent(urlIn)}`);
return true;
}
return false;