From a88a9ccc866057590d74b65397ee7db89bed9653 Mon Sep 17 00:00:00 2001 From: kinggo Date: Sat, 10 Dec 2022 20:30:12 +0800 Subject: [PATCH] optimize: use fasthttp.AddMissingPort --- client.go | 16 +--------------- client_test.go | 5 ----- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/client.go b/client.go index 02816db228..f2fbec41a0 100644 --- a/client.go +++ b/client.go @@ -8,11 +8,9 @@ import ( "fmt" "io" "mime/multipart" - "net" "os" "path/filepath" "strconv" - "strings" "sync" "time" @@ -202,7 +200,7 @@ func (a *Agent) Parse() error { } a.HostClient = &fasthttp.HostClient{ - Addr: addMissingPort(string(uri.Host()), isTLS), + Addr: fasthttp.AddMissingPort(string(uri.Host()), isTLS), Name: name, NoDefaultUserAgentHeader: a.NoDefaultUserAgentHeader, IsTLS: isTLS, @@ -211,18 +209,6 @@ func (a *Agent) Parse() error { return nil } -func addMissingPort(addr string, isTLS bool) string { - n := strings.Index(addr, ":") - if n >= 0 { - return addr - } - port := 80 - if isTLS { - port = 443 - } - return net.JoinHostPort(addr, strconv.Itoa(port)) -} - /************************** Header Setting **************************/ // Set sets the given 'key: value' header. diff --git a/client_test.go b/client_test.go index c8e93c5e85..323881127a 100644 --- a/client_test.go +++ b/client_test.go @@ -1134,11 +1134,6 @@ func Test_Client_Agent_Parse(t *testing.T) { utils.AssertEqual(t, nil, a.Parse()) } -func Test_AddMissingPort_TLS(t *testing.T) { - addr := addMissingPort("example.com", true) - utils.AssertEqual(t, "example.com:443", addr) -} - func testAgent(t *testing.T, handler Handler, wrapAgent func(agent *Agent), excepted string, count ...int) { t.Parallel()