Skip to content

Commit

Permalink
optimize: use fasthttp.AddMissingPort (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jin-gou committed Dec 10, 2022
1 parent affa759 commit 2e3f73c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
16 changes: 1 addition & 15 deletions client.go
Expand Up @@ -8,11 +8,9 @@ import (
"fmt"
"io"
"mime/multipart"
"net"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions client_test.go
Expand Up @@ -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()

Expand Down

0 comments on commit 2e3f73c

Please sign in to comment.