From 9036eba0b48530553c08dc107d9aa1d66a1cc7cd Mon Sep 17 00:00:00 2001 From: xingcxb Date: Tue, 31 Oct 2023 14:57:35 +0800 Subject: [PATCH] fix: some fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修正http proxy传参时header为nil导致的bug --- _examples/core/http_test.go | 2 +- core/httpKit/httpClientKit.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/_examples/core/http_test.go b/_examples/core/http_test.go index 592a859..b84761b 100644 --- a/_examples/core/http_test.go +++ b/_examples/core/http_test.go @@ -55,7 +55,7 @@ func TestHttpProxyPostFull(t *testing.T) { func TestHttpProxyBasic(t *testing.T) { fmt.Println(httpKit.HttpProxyBasic("https://cip.cc", http.MethodGet, nil, nil, "", 300, "http", - "", "", "255.255.255.255:52724")) + "", "", "255.255.255.255:29093")) } func TestUA(t *testing.T) { diff --git a/core/httpKit/httpClientKit.go b/core/httpKit/httpClientKit.go index 601296d..3f2815f 100644 --- a/core/httpKit/httpClientKit.go +++ b/core/httpKit/httpClientKit.go @@ -142,6 +142,10 @@ func HttpBasic(urlString, httpMethod string, headers, paramMap map[string]string } bodyReader := strings.NewReader(body) req, _ := http.NewRequest(httpMethod, urlString, bodyReader) + if headers == nil { + // 如果headers为空,初始化 + headers = make(map[string]string, 0) + } for k, v := range headers { req.Header.Add(k, v) } @@ -275,6 +279,10 @@ func HttpProxyBasic(urlStr, httpMethod string, headers, paramMap map[string]stri return headers, "", err } // 获取新的headers数据 + if headers == nil { + // 如果headers为空,初始化 + headers = make(map[string]string, 0) + } for k, v := range res.Header { headers[k] = v[0] }