- ModelChannel 新增 proxy_url 字段,v48 迁移自动加列 - outbound 新增 OutboundHTTPClientWithProxy,socks5/socks5h/http/https 均支持; 目标主机名不做本地解析,直接交给代理服务器远端解析,本地开启 TUN/VPN 时仍可用 - 系统代理、Provider 出站、管理员模型测试路径均使用渠道级代理 - 渠道管理表单新增"代理地址"输入框,留空回退全局代理
86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
|
|
"yingce/backend/internal/outbound"
|
|
)
|
|
|
|
// Outbound 符号从 internal/outbound 再导出,保持 service/handler 调用面稳定。
|
|
type OutboundHeader = outbound.OutboundHeader
|
|
|
|
const (
|
|
CustomRelayHeadersHeader = outbound.CustomRelayHeadersHeader
|
|
DefaultOutboundUserAgent = outbound.DefaultOutboundUserAgent
|
|
)
|
|
|
|
func ValidateOutboundURL(rawURL string) (*url.URL, error) {
|
|
parsed, err := outbound.ValidateOutboundURL(rawURL)
|
|
return parsed, mapOutboundError(err)
|
|
}
|
|
|
|
func ValidateCustomRelayURL(rawURL string) (*url.URL, error) {
|
|
parsed, err := outbound.ValidateCustomRelayURL(rawURL)
|
|
return parsed, mapOutboundError(err)
|
|
}
|
|
|
|
func OutboundHTTPClient(timeout time.Duration) *http.Client {
|
|
return outbound.OutboundHTTPClient(timeout)
|
|
}
|
|
|
|
func OutboundHTTPClientWithProxy(timeout time.Duration, proxyURL string) *http.Client {
|
|
return outbound.OutboundHTTPClientWithProxy(timeout, proxyURL)
|
|
}
|
|
|
|
func ApplyDefaultOutboundHeaders(req *http.Request) {
|
|
outbound.ApplyDefaultOutboundHeaders(req)
|
|
}
|
|
|
|
func NormalizeOutboundHeaders(headers []OutboundHeader) ([]OutboundHeader, error) {
|
|
normalized, err := outbound.NormalizeOutboundHeaders(headers)
|
|
return normalized, mapOutboundError(err)
|
|
}
|
|
|
|
func ApplyOutboundHeaders(req *http.Request, headers []OutboundHeader) {
|
|
outbound.ApplyOutboundHeaders(req, headers)
|
|
}
|
|
|
|
func EncodeOutboundHeadersJSON(headers []OutboundHeader) (string, error) {
|
|
encoded, err := outbound.EncodeOutboundHeadersJSON(headers)
|
|
return encoded, mapOutboundError(err)
|
|
}
|
|
|
|
func ParseOutboundHeadersJSON(raw string) ([]OutboundHeader, error) {
|
|
decoded, err := outbound.ParseOutboundHeadersJSON(raw)
|
|
return decoded, mapOutboundError(err)
|
|
}
|
|
|
|
func DecodeRelayOutboundHeaders(encoded string) ([]OutboundHeader, error) {
|
|
decoded, err := outbound.DecodeRelayOutboundHeaders(encoded)
|
|
return decoded, mapOutboundError(err)
|
|
}
|
|
|
|
func CustomRelayHTTPClient(timeout time.Duration) *http.Client {
|
|
return outbound.CustomRelayHTTPClient(timeout)
|
|
}
|
|
|
|
func ValidateOutboundHost(host string) error {
|
|
return mapOutboundError(outbound.ValidateOutboundHost(host))
|
|
}
|
|
|
|
func AllowedPrivateUpstreamHost(host string) bool {
|
|
return outbound.AllowedPrivateUpstreamHost(host)
|
|
}
|
|
|
|
func mapOutboundError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
if req, ok := err.(*outbound.BadRequestError); ok {
|
|
return BadAuthRequest(req.Message)
|
|
}
|
|
return err
|
|
}
|