Wei-Shaw/sub2api · error
proxy protocol is required
Error message
proxy protocol is required
What it means
Returned by validateDataProxy (backend/internal/handler/admin/account_data.go:656) for a proxy entry whose protocol is empty after TrimSpace. Protocol is the first per-proxy field checked; it must then be one of http, https, socks5, socks5h (a different error, 'proxy protocol is invalid', covers unknown values).
Source
Thrown at backend/internal/handler/admin/account_data.go:656
func validateDataHeader(payload DataPayload) error {
if payload.Type != "" && payload.Type != dataType && payload.Type != legacyDataType {
return fmt.Errorf("unsupported data type: %s", payload.Type)
}
if payload.Version != 0 && payload.Version != dataVersion {
return fmt.Errorf("unsupported data version: %d", payload.Version)
}
if payload.Proxies == nil {
return errors.New("proxies is required")
}
if payload.Accounts == nil {
return errors.New("accounts is required")
}
return nil
}
func validateDataProxy(item DataProxy) error {
if strings.TrimSpace(item.Protocol) == "" {
return errors.New("proxy protocol is required")
}
if strings.TrimSpace(item.Host) == "" {
return errors.New("proxy host is required")
}
if item.Port <= 0 || item.Port > 65535 {
return errors.New("proxy port is invalid")
}
switch item.Protocol {
case "http", "https", "socks5", "socks5h":
default:
return fmt.Errorf("proxy protocol is invalid: %s", item.Protocol)
}
if item.Status != "" {
normalizedStatus := normalizeProxyStatus(item.Status)
if normalizedStatus != service.StatusActive && normalizedStatus != "inactive" {
return fmt.Errorf("proxy status is invalid: %s", item.Status)
}
}View on GitHub (pinned to 073e92d171)
Solutions
- Set protocol to one of http, https, socks5, socks5h on every proxies[] entry.
- If your source data uses 'scheme', map it to 'protocol' when building the payload.
- Trim inputs client-side before submit.
Example fix
// before
{ "host": "127.0.0.1", "port": 7890 }
// after
{ "protocol": "socks5", "host": "127.0.0.1", "port": 7890 } Defensive patterns
Strategy: validation
Validate before calling
const PROXY_PROTOCOLS = new Set(['http', 'https', 'socks5', 'socks5h'])
function hasProxyProtocol(entry: Record<string, unknown>): boolean {
return typeof entry.protocol === 'string' && PROXY_PROTOCOLS.has(entry.protocol.trim())
} Type guard
function isPlausibleDataProxy(e: unknown): e is { protocol: string; host: string; port: number } {
if (typeof e !== 'object' || e === null) return false
const o = e as Record<string, unknown>
return typeof o.protocol === 'string' && o.protocol.trim() !== '' &&
typeof o.host === 'string' && o.host.trim() !== '' &&
typeof o.port === 'number' && Number.isInteger(o.port) && o.port >= 1 && o.port <= 65535
} Prevention
- Normalize your source's 'scheme' field to 'protocol' when building payloads.
- Offer a fixed dropdown (http/https/socks5/socks5h) instead of free text.
- Trim whitespace on all string fields before submit.
When it happens
Trigger: A proxies[] entry with protocol missing, empty string, or only whitespace; schema renamed (scheme vs protocol) so the field is never populated.
Common situations: Exporting from a tool that calls it 'scheme'; hand-written proxy entries; trailing-whitespace protocol from a form input.
Related errors
- proxy host is required
- proxy port is invalid
- 空 JSON 内容
- agent identity 缺少必要字段
- agent identity private key 格式无效
AI-assisted analysis of Wei-Shaw/sub2api@073e92d171 (2026-08-15).
Data as JSON: /api/errors/e2ec87325a569dd3.
Report an issue: GitHub.