feat: add custom User-Agent support for profiles#2127
Open
MacroVoid wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: Per-Profile Custom User-Agent Support
Summary
Introduces per-profile User-Agent override capability, enabling fine-grained control over HTTP headers used during profile downloads and updates. This addresses compatibility issues with subscription providers that enforce strict UA-based access policies.
Motivation
The existing implementation applies a single global User-Agent to all outbound profile requests. A subset of proxy subscription providers requires specific UA strings — such as
Clash.Meta,Clash for Windows, or standard browser identifiers — to serve well-formed configuration payloads or to pass provider-side access controls. A global UA cannot satisfy these requirements simultaneously across multiple profiles.Changes
Data Layer
userAgentfield to theProfilemodel (freezed-managed).user_agentcolumn on theprofilestable.onUpgrademigration handler: duplicate-columnSqliteExceptionis caught and suppressed, preventing crashes on existing database instances.freezed,json_serializable, anddriftderived files.Network Layer (
lib/common/request.dart)Requestutility to conditionally inject aUser-Agentheader into outgoingdiorequests when a profile-level override is present.State Management (
lib/providers/action.dart)ProfilesActionto accept and propagate auserAgentparameter through both the URL-based profile creation and the manual profile update flows.Stringto(String, String?)tuple to carry both the URL and the selected UA in a strongly-typed manner.UI (
lib/views/config/general.dart)UaDialog— new reusable dialog component providing:URLFormDialog— added UA selection control to the "Add Profile" flow.EditProfileView— added UA configuration field to the "Edit Profile" screen; displaysGlobalas fallback when no override is configured.ListItem, standard dialog patterns).Compatibility
user_agentcolumn created as part of initial schema.onUpgrademigration adds column; existing rows default toNULL(global UA).feat: 每个配置文件独立 User-Agent 支持
概述
引入基于配置文件级别的 User-Agent 覆盖机制,允许对每个配置文件的下载和更新请求独立指定 HTTP
User-Agent头。此功能旨在解决对 UA 有强制要求的订阅服务商的兼容性问题。背景
现有实现对所有出站配置文件请求统一使用全局 User-Agent。部分代理订阅服务商要求请求携带特定 UA 字符串(如
Clash.Meta、Clash for Windows或标准浏览器标识),以返回有效的配置内容或通过访问控制。单一的全局 UA 无法同时满足多个配置文件的差异化需求。变更详情
数据层
Profile模型(由freezed管理)中新增可选字段userAgent。profiles表中新增user_agent列。onUpgrade迁移策略:捕获并忽略因重复列触发的SqliteException,防止现有数据库在应用初始化时崩溃。freezed、json_serializable和drift的代码生成文件。网络层(
lib/common/request.dart)Request工具类:当配置文件存在 UA 覆盖值时,在dio出站请求中动态注入User-Agent请求头。状态管理(
lib/providers/action.dart)ProfilesAction,在通过 URL 创建配置文件和手动更新配置文件的流程中,接受并传递userAgent参数。String重构为强类型元组(String, String?),以同时携带 URL 与所选 UA。UI 层(
lib/views/config/general.dart)UaDialog— 新增可复用的 UA 选择对话框,支持:URLFormDialog— 在"添加配置"流程中新增 UA 选择控件。EditProfileView— 在"编辑配置"界面新增 UA 配置项;未设置覆盖值时,优雅回退并显示Global(全局默认)标识。ListItem、标准对话框样式)保持一致。兼容性说明
user_agent列作为初始 Schema 的一部分创建。onUpgrade迁移自动添加该列;现有行默认为NULL(使用全局 UA)。