Skip to content

feat: enhance proxy management and configuration #8164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 16, 2025
Merged

Conversation

beyondkmp
Copy link
Collaborator

  • Added support for new proxy modes and improved proxy configuration handling.
  • Replaced AxiosProxy with direct axios usage for HTTP requests.
  • Introduced fetch-socks and undici for better proxy handling.
  • Updated IPC and ConfigManager to accommodate new proxy settings.
  • Removed deprecated AxiosProxy service to streamline codebase.

What this PR does

Before this PR:

全局代理有些小问题

After this PR:

支持全局代理

Fixes #

Why we need it and why it was done in this way

The following tradeoffs were made:

The following alternatives were considered:

Links to places where the discussion took place:

Breaking changes

If this PR introduces breaking changes, please describe the changes and the impact on users.

Special notes for your reviewer

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note


- Added support for new proxy modes and improved proxy configuration handling.
- Replaced AxiosProxy with direct axios usage for HTTP requests.
- Introduced fetch-socks and undici for better proxy handling.
- Updated IPC and ConfigManager to accommodate new proxy settings.
- Removed deprecated AxiosProxy service to streamline codebase.
@beyondkmp
Copy link
Collaborator Author

beyondkmp commented Jul 15, 2025

nodejs里面有 http/https, fetch两种库。

  1. http/https,直接替换掉原始方法,添加agent来请求,可以解决axios, node-fetch等库
  2. fetch,是通过uundici实现的setGlobalDispatcher来实现的。

electron的其它network的proxy有两类,一类是session.setProxy(主要针对所有render进程),一类是app.setProxy(主进程和utility进程的net.fetch)

测试范围

  1. webdav - 用的node-fetch(https/http)
  2. 测试计划 - 用的原生fetch
  3. S3 client
  4. 知识库
  5. 其它网络请示。

参考

  1. https://github.com/gajus/global-agent/blob/master/src/factories/createGlobalProxyAgent.ts
  2. http: support HTTP[S]_PROXY environment variables in fetch nodejs/node#57165
  3. ProxyAgent: support socks5 protocol nodejs/undici#2224
  4. https://github.com/Kaciras/fetch-socks
  5. https://github.com/TooTallNate/proxy-agents/tree/main

@beyondkmp
Copy link
Collaborator Author

这个需要多测试看下,因为整个project还是有很多不同的库都会有网络请求的。

- Introduced a new mechanism to monitor system proxy changes and update configurations accordingly.
- Enhanced the configureProxy method to prevent concurrent executions and added error logging with electron-log.
- Refactored proxy handling logic to streamline the setting of global and session proxies.
- Removed deprecated methods related to proxy management for cleaner code.
@beyondkmp
Copy link
Collaborator Author

@GeorgeDong32 有空也帮忙看看s3的走代理会有问题不?我看源码这个库走的是nodejs的https库。

@beyondkmp beyondkmp added this to the v1.5.1 milestone Jul 15, 2025
@DeJeune
Copy link
Collaborator

DeJeune commented Jul 15, 2025

可以多测试下webdav

- Modified the app's ready event to check for 'direct' mode before configuring the proxy.
- Ensured that the proxy configuration is only applied when necessary, improving efficiency.
@beyondkmp
Copy link
Collaborator Author

beyondkmp commented Jul 15, 2025

可以多测试下webdav

我这边的webdav都正常了,不过我是正常的nas的webdav,不知道还有其它什么的不?都是用的同一个库webdav client,应该是其它的也不会有问题了。

@DeJeune
Copy link
Collaborator

DeJeune commented Jul 15, 2025

跑一个apache的webdav?

@beyondkmp
Copy link
Collaborator Author

之前出问题的apache的webdav?

@beyondkmp
Copy link
Collaborator Author

看了下之前的历史,那个问题不是代理引起的,是用户用了https,但是是用的自签名的证书,导致一直连接不上的。
#3144

image

@DeJeune
Copy link
Collaborator

DeJeune commented Jul 15, 2025

看了下之前的历史,那个问题不是代理引起的,是用户用了https,但是是用的自签名的证书,导致一直连接不上的。 #3144

image

可以加一个选项允许自签名证书

@DeJeune
Copy link
Collaborator

DeJeune commented Jul 15, 2025

下一步再做支持用户名和密码的代理?

@beyondkmp
Copy link
Collaborator Author

下一步再做支持用户名和密码的代理?

image env proxy看起来是默认都支持了。socks这边我再加下global的。

- Added userId and password fields to the proxy configuration for SOCKS connections.
- Improved handling of proxy credentials to allow for authenticated proxy usage.
@beyondkmp
Copy link
Collaborator Author

beyondkmp commented Jul 15, 2025

看了下之前的历史,那个问题不是代理引起的,是用户用了https,但是是用的自签名的证书,导致一直连接不上的。 #3144
image

可以加一个选项允许自签名证书

现在默认是允许,之前做过一次了https://github.com/CherryHQ/cherry-studio/pull/6784/files 优化。

这个选项要加的话,目前看起来只能加在代理这边的设置里面了。

@DeJeune
Copy link
Collaborator

DeJeune commented Jul 15, 2025

CleanShot 2025-07-15 at 14 30 13@2x

之前反馈的

@beyondkmp
Copy link
Collaborator Author

CleanShot 2025-07-15 at 14 30 13@2x 之前反馈的

这是哪个issue?

@DeJeune
Copy link
Collaborator

DeJeune commented Jul 15, 2025

#831

@DeJeune
Copy link
Collaborator

DeJeune commented Jul 15, 2025

下一步再做支持用户名和密码的代理?

image env proxy看起来是默认都支持了。socks这边我再加下global的。

系统代理能识别到user和password吗?

@DeJeune
Copy link
Collaborator

DeJeune commented Jul 15, 2025

下一步再做支持用户名和密码的代理?

image env proxy看起来是默认都支持了。socks这边我再加下global的。

系统代理能识别到user和password吗?

如果在系统代理下面,应该是需要一个弹窗的,来填写用户和密码

@beyondkmp
Copy link
Collaborator Author

beyondkmp commented Jul 15, 2025

下一步再做支持用户名和密码的代理?

image env proxy看起来是默认都支持了。socks这边我再加下global的。

系统代理能识别到user和password吗?

识别不到。而且windows/mac/linux都不一样, 要自动从系统获取还比较难。看起来直接再加用户名和password的配置了,这样最简单。

看起来要支持系统的user和password后面还要再搞一个PR来完善了。

Copy link
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows测试S3、WebDAV、对话和知识库没有异常

@beyondkmp
Copy link
Collaborator Author

@DeJeune 好像没有必要支持socks/http proxy的username和password,这些都是没有加密的,在公网一般不会搞这样的proxy,直接抓包就能得到username和password。内网搞的一般也没有必要加了。所以这块后面再看下具体的用户需求了。

…n logic

- Eliminated the setProxy and getProxy methods from ConfigManager to simplify the proxy configuration process.
- Updated ProxyManager to initialize with a default proxy configuration and removed unnecessary checks for 'direct' mode during initialization.
- Enhanced logging for proxy configuration changes to improve traceability.
@beyondkmp
Copy link
Collaborator Author

beyondkmp commented Jul 15, 2025

windows系统socks代理设置

image

…port

- Added handling for self-signed certificates in ProxyManager to allow secure connections with custom agents.
- Updated WebDav configuration to include an https.Agent with rejectUnauthorized set to false, facilitating connections to servers with self-signed certificates.
@DeJeune DeJeune merged commit 2d6c05e into CherryHQ:main Jul 16, 2025
1 check passed
beyondkmp added a commit to beyondkmp/cherry-studio that referenced this pull request Jul 17, 2025
* feat: enhance proxy management and configuration

- Added support for new proxy modes and improved proxy configuration handling.
- Replaced AxiosProxy with direct axios usage for HTTP requests.
- Introduced fetch-socks and undici for better proxy handling.
- Updated IPC and ConfigManager to accommodate new proxy settings.
- Removed deprecated AxiosProxy service to streamline codebase.

* format code

* feat: improve proxy configuration and monitoring

- Introduced a new mechanism to monitor system proxy changes and update configurations accordingly.
- Enhanced the configureProxy method to prevent concurrent executions and added error logging with electron-log.
- Refactored proxy handling logic to streamline the setting of global and session proxies.
- Removed deprecated methods related to proxy management for cleaner code.

* update yarn.lock

* fix: update proxy configuration logic to handle direct mode

- Modified the app's ready event to check for 'direct' mode before configuring the proxy.
- Ensured that the proxy configuration is only applied when necessary, improving efficiency.

* feat: enhance proxy configuration to support authentication

- Added userId and password fields to the proxy configuration for SOCKS connections.
- Improved handling of proxy credentials to allow for authenticated proxy usage.

* refactor: remove deprecated proxy methods and streamline configuration logic

- Eliminated the setProxy and getProxy methods from ConfigManager to simplify the proxy configuration process.
- Updated ProxyManager to initialize with a default proxy configuration and removed unnecessary checks for 'direct' mode during initialization.
- Enhanced logging for proxy configuration changes to improve traceability.

* format code

* feat: enhance WebDav and ProxyManager for self-signed certificate support

- Added handling for self-signed certificates in ProxyManager to allow secure connections with custom agents.
- Updated WebDav configuration to include an https.Agent with rejectUnauthorized set to false, facilitating connections to servers with self-signed certificates.

* delete global setting for rejectUnauthorized
kangfenmao added a commit that referenced this pull request Jul 21, 2025
* chore: update electron to version 37.1.0 and add node-abi dependency

* chore: specify Node.js engine version requirement in package.json

* hotfix: error on deleting assistant (#8190)

fix: error on deleting assistant

* Fix/mcp bug (#8189)

* feat(models): enhance function calling model detection and update migration logic

- Added support for 'gemini-1' in FUNCTION_CALLING_EXCLUDED_MODELS.
- Updated isFunctionCallingModel to handle optional model input.
- Modified migration logic to change tool use mode for assistants using function calling models.

* feat(models): add new models to vision and function calling lists

- Added 'kimi-thinking-preview' to visionAllowedModels.
- Added 'kimi-k2' to FUNCTION_CALLING_MODELS.
- Updated migration logic to ensure compatibility with new model settings.

* refactor(TextChunkMiddleware): streamline text accumulation logic and improve response handling

- Simplified the logic for accumulating text content and updating the internal state.
- Ensured that the final text is consistently used in response callbacks.
- Removed redundant code for handling text completion in the ToolUseExtractionMiddleware.
- Added mock state for MCP tools in tests to enhance coverage for tool use extraction.

* refactor(BaseApiClient): remove unused content extraction utility

- Replaced the usage of getContentWithTools with getMainTextContent in the getMessageContent method.
- Cleaned up imports by removing the unused getContentWithTools function.

* refactor: custom mini app loading logic (#8181)

* refactor: custom mini app loading logic

Replaces try-catch with an explicit file existence check before reading 'custom-minapps.json'. Ensures the file is created with an empty array if it does not exist, improving clarity and error handling.

* refactor: custom mini app loading logic

Simplifies the loading of custom mini apps by removing the explicit file existence check and handling the read failure case directly. If reading the file fails, an empty array is written and returned.

* fix: improve error handling in file reading for custom mini apps

* Revert "feat: optimize minapp cache with LRU (#8160)" (#8205)

This reverts commit f0043b4.

* feat: add support for 302AI provider in MCP settings (#7755)

* feat: add support for 302AI provider in MCP settings

- Introduced new provider for 302AI, including token management and server synchronization functionality.
- Updated SyncServersPopup to integrate 302AI provider.
- Added new file for 302AI provider utilities, including token storage and server fetching logic.

* fix: re-merge main

* chore: update check-i18n scripts and remove duplicate keys (#8203)

* chore(version): 1.5.0

* fix: handle mentions when resending message (#7819)

* fix(messageThunk): 修复重置消息时模型未正确继承的问题

* fix(消息重发): 修复重发消息时模型选择逻辑

确保当原始消息模型被提及时才使用该模型,否则使用助手默认模型

* style(PasteService): 统一文件换行符为LF格式

* Revert "style(PasteService): 统一文件换行符为LF格式"

This reverts commit 37a1443.

* refactor(messageThunk): 优化消息重发逻辑,分离新旧消息处理

将消息重发逻辑拆分为处理已有消息和新增提及模型消息两部分
简化条件判断,移除冗余代码

* style(messageThunk): 移除多余的空行

* fix(消息重传): 单条无提及消息重传时使用助手模型

当重传单条无提及消息时,使用助手模型进行重传,其他情况保持原有逻辑

* Revert "fix(消息重传): 单条无提及消息重传时使用助手模型"

This reverts commit 2e36917.

* fix(消息重发): 修改重发消息时模型设置逻辑

* feat: enhance proxy management and configuration (#8164)

* feat: enhance proxy management and configuration

- Added support for new proxy modes and improved proxy configuration handling.
- Replaced AxiosProxy with direct axios usage for HTTP requests.
- Introduced fetch-socks and undici for better proxy handling.
- Updated IPC and ConfigManager to accommodate new proxy settings.
- Removed deprecated AxiosProxy service to streamline codebase.

* format code

* feat: improve proxy configuration and monitoring

- Introduced a new mechanism to monitor system proxy changes and update configurations accordingly.
- Enhanced the configureProxy method to prevent concurrent executions and added error logging with electron-log.
- Refactored proxy handling logic to streamline the setting of global and session proxies.
- Removed deprecated methods related to proxy management for cleaner code.

* update yarn.lock

* fix: update proxy configuration logic to handle direct mode

- Modified the app's ready event to check for 'direct' mode before configuring the proxy.
- Ensured that the proxy configuration is only applied when necessary, improving efficiency.

* feat: enhance proxy configuration to support authentication

- Added userId and password fields to the proxy configuration for SOCKS connections.
- Improved handling of proxy credentials to allow for authenticated proxy usage.

* refactor: remove deprecated proxy methods and streamline configuration logic

- Eliminated the setProxy and getProxy methods from ConfigManager to simplify the proxy configuration process.
- Updated ProxyManager to initialize with a default proxy configuration and removed unnecessary checks for 'direct' mode during initialization.
- Enhanced logging for proxy configuration changes to improve traceability.

* format code

* feat: enhance WebDav and ProxyManager for self-signed certificate support

- Added handling for self-signed certificates in ProxyManager to allow secure connections with custom agents.
- Updated WebDav configuration to include an https.Agent with rejectUnauthorized set to false, facilitating connections to servers with self-signed certificates.

* delete global setting for rejectUnauthorized

* chore: update dependencies in package.json and yarn.lock

- Upgraded electron from 37.1.0 to 37.2.3.
- Updated electron-vite from 3.1.0 to 4.0.0.
- Various dependency updates in yarn.lock to align with the new versions, including Babel packages and esbuild to 0.25.6.

---------

Co-authored-by: one <[email protected]>
Co-authored-by: SuYao <[email protected]>
Co-authored-by: 自由的世界人 <[email protected]>
Co-authored-by: fullex <[email protected]>
Co-authored-by: ⌞L⌝ <[email protected]>
Co-authored-by: kangfenmao <[email protected]>
Co-authored-by: Phantom <[email protected]>
@beyondkmp beyondkmp deleted the proxy branch July 29, 2025 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants