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 cc04bce commit 34b3f3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 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 @@ -2008,7 +2008,7 @@ func (c *HostClient) getClientName() []byte {
// AddMissingPort adds a port to a host if it is missing.
// A literal IPv6 address in hostport must be enclosed in square
// brackets, as in "[::1]:80", "[::1%lo0]:80".
func addMissingPort(addr string, isTLS bool) string {
func AddMissingPort(addr string, isTLS bool) string {
columnPos := strings.IndexByte(addr, ':')
if columnPos >= 0 {
endOfV6 := strings.IndexByte(addr[columnPos:], ']')
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 @@ -3021,8 +3021,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 34b3f3c

Please sign in to comment.