Skip to content

Commit

Permalink
client.go Make addMissingPort() public
Browse files Browse the repository at this point in the history
It's needed for those who creates the instance of the HostClient manually.
  • Loading branch information
stokito committed Nov 25, 2022
1 parent 51384ce commit 606562f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions client.go
Expand Up @@ -494,7 +494,7 @@ func (c *Client) Do(req *Request, resp *Response) error {
hc := m[string(host)]
if hc == nil {
hc = &HostClient{
Addr: addMissingPort(string(host), isTLS),
Addr: AddMissingPort(string(host), isTLS),
Name: c.Name,
NoDefaultUserAgentHeader: c.NoDefaultUserAgentHeader,
Dial: c.Dial,
Expand Down Expand Up @@ -1967,7 +1967,7 @@ func dialAddr(addr string, dial DialFunc, dialDualStack, isTLS bool, tlsConfig *
} else {
dial = Dial
}
addr = addMissingPort(addr, isTLS)
addr = AddMissingPort(addr, isTLS)
}
conn, err := dial(addr)
if err != nil {
Expand Down Expand Up @@ -2005,7 +2005,8 @@ func (c *HostClient) getClientName() []byte {
return clientName
}

func addMissingPort(addr string, isTLS bool) string {
// AddMissingPort adds a port to a host if it is missing.
func AddMissingPort(addr string, isTLS bool) string {
addrLen := len(addr)
if addrLen == 0 {
return addr
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Expand Up @@ -2972,7 +2972,7 @@ func TestHttpsRequestWithoutParsedURL(t *testing.T) {
}
}

func Test_addMissingPort(t *testing.T) {
func Test_AddMissingPort(t *testing.T) {
type args struct {
addr string
isTLS bool
Expand Down Expand Up @@ -3029,8 +3029,8 @@ func Test_addMissingPort(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := addMissingPort(tt.args.addr, tt.args.isTLS); got != tt.want {
t.Errorf("addMissingPort() = %v, want %v", got, tt.want)
if got := AddMissingPort(tt.args.addr, tt.args.isTLS); got != tt.want {
t.Errorf("AddMissingPort() = %v, want %v", got, tt.want)
}
})
}
Expand Down

0 comments on commit 606562f

Please sign in to comment.