Skip to content

Commit

Permalink
fix: some fix
Browse files Browse the repository at this point in the history
1. 修正http proxy传参时header为nil导致的bug
  • Loading branch information
xingcxb committed Oct 31, 2023
1 parent bb59ccd commit 9036eba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _examples/core/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions core/httpKit/httpClientKit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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]
}
Expand Down

0 comments on commit 9036eba

Please sign in to comment.