fix headers in clash sub #1126

This commit is contained in:
Alireza Ahmadi 2026-06-24 17:53:24 +02:00
parent 3cf47bb501
commit b04dec5c80

View file

@ -296,8 +296,29 @@ func (s *ClashService) ConvertToClashMeta(outbounds *[]map[string]interface{}, b
if path, ok := transport["path"].(string); ok {
wsOpts["path"] = path
}
if headers, ok := transport["headers"].([]interface{}); ok {
wsOpts["headers"] = headers
wsHeaders := make(map[string]interface{})
if headers, ok := transport["headers"].(map[string]interface{}); ok {
for k, v := range headers {
if arr, ok := v.([]interface{}); ok {
if len(arr) > 0 {
wsHeaders[k] = arr[0]
}
} else {
wsHeaders[k] = v
}
}
}
if _, hasHost := wsHeaders["Host"]; !hasHost {
if host, ok := transport["host"].(string); ok && host != "" {
wsHeaders["Host"] = host
} else if isTls {
if sni, ok := tls["server_name"].(string); ok && sni != "" {
wsHeaders["Host"] = sni
}
}
}
if len(wsHeaders) > 0 {
wsOpts["headers"] = wsHeaders
}
if ed, ok := transport["early_data_header_name"].(string); ok {
wsOpts["early-data-header-name"] = ed