From b04dec5c809dc100fcf411a6382ae3b3648ae684 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Wed, 24 Jun 2026 17:53:24 +0200 Subject: [PATCH] fix headers in clash sub #1126 --- sub/clashService.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/sub/clashService.go b/sub/clashService.go index f403117..a542794 100644 --- a/sub/clashService.go +++ b/sub/clashService.go @@ -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