From 606562fd59bbd372ef221b9d89c398092a0e182e Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 25 Nov 2022 14:24:30 +0200 Subject: [PATCH] client.go Make addMissingPort() public It's needed for those who creates the instance of the HostClient manually. --- client.go | 7 ++++--- client_test.go | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 6f854f80ca..dc41201491 100644 --- a/client.go +++ b/client.go @@ -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, @@ -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 { @@ -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 diff --git a/client_test.go b/client_test.go index 8bf6d8145b..d8d0ab9885 100644 --- a/client_test.go +++ b/client_test.go @@ -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 @@ -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) } }) }