This commit is contained in:
世界 2023-10-08 22:05:03 +08:00
parent aa3255f763
commit 1329edf42e
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
6 changed files with 14 additions and 12 deletions

View File

@ -31,5 +31,5 @@ type HTTPOutboundOptions struct {
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"` TLS *OutboundTLSOptions `json:"tls,omitempty"`
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
Headers OutboundHeader `json:"headers,omitempty"` Headers HTTPHeader `json:"headers,omitempty"`
} }

View File

@ -236,12 +236,14 @@ func DNSQueryTypeToString(queryType uint16) string {
return F.ToString(queryType) return F.ToString(queryType)
} }
type OutboundHeader map[string]Listable[string] type HTTPHeader map[string]Listable[string]
func (h OutboundHeader) HTTPHeader() http.Header { func (h HTTPHeader) Build() http.Header {
header := make(http.Header) header := make(http.Header)
for name, values := range h { for name, values := range h {
header[http.CanonicalHeaderKey(name)] = values for _, value := range values {
header.Add(name, value)
}
} }
return header return header
} }

View File

@ -64,16 +64,16 @@ type V2RayHTTPOptions struct {
Host Listable[string] `json:"host,omitempty"` Host Listable[string] `json:"host,omitempty"`
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
Method string `json:"method,omitempty"` Method string `json:"method,omitempty"`
Headers OutboundHeader `json:"headers,omitempty"` Headers HTTPHeader `json:"headers,omitempty"`
IdleTimeout Duration `json:"idle_timeout,omitempty"` IdleTimeout Duration `json:"idle_timeout,omitempty"`
PingTimeout Duration `json:"ping_timeout,omitempty"` PingTimeout Duration `json:"ping_timeout,omitempty"`
} }
type V2RayWebsocketOptions struct { type V2RayWebsocketOptions struct {
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
Headers OutboundHeader `json:"headers,omitempty"` Headers HTTPHeader `json:"headers,omitempty"`
MaxEarlyData uint32 `json:"max_early_data,omitempty"` MaxEarlyData uint32 `json:"max_early_data,omitempty"`
EarlyDataHeaderName string `json:"early_data_header_name,omitempty"` EarlyDataHeaderName string `json:"early_data_header_name,omitempty"`
} }
type V2RayQUICOptions struct{} type V2RayQUICOptions struct{}

View File

@ -48,7 +48,7 @@ func NewHTTP(ctx context.Context, router adapter.Router, logger log.ContextLogge
Username: options.Username, Username: options.Username,
Password: options.Password, Password: options.Password,
Path: options.Path, Path: options.Path,
Headers: options.Headers.HTTPHeader(), Headers: options.Headers.Build(),
}), }),
}, nil }, nil
} }

View File

@ -64,7 +64,7 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
serverAddr: serverAddr, serverAddr: serverAddr,
host: options.Host, host: options.Host,
method: options.Method, method: options.Method,
headers: options.Headers.HTTPHeader(), headers: options.Headers.Build(),
transport: transport, transport: transport,
http2: tlsConfig != nil, http2: tlsConfig != nil,
} }

View File

@ -55,7 +55,7 @@ func NewServer(ctx context.Context, options option.V2RayHTTPOptions, tlsConfig t
host: options.Host, host: options.Host,
path: options.Path, path: options.Path,
method: options.Method, method: options.Method,
headers: options.Headers.HTTPHeader(), headers: options.Headers.Build(),
} }
if server.method == "" { if server.method == "" {
server.method = "PUT" server.method = "PUT"