diff options
author | Sergey Ponomarev <stokito@gmail.com> | 2022-11-28 09:06:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-28 08:06:09 +0100 |
commit | c50de95952581388eec6e67a8f7a651d80c37a0b (patch) | |
tree | 5fdc17e9a98f881b823f2ae1c10489abf779f6a6 /client_test.go | |
parent | feat: add ShutdownWithContext (#1383) (diff) | |
download | fasthttp-c50de95952581388eec6e67a8f7a651d80c37a0b.tar.gz fasthttp-c50de95952581388eec6e67a8f7a651d80c37a0b.tar.bz2 fasthttp-c50de95952581388eec6e67a8f7a651d80c37a0b.zip |
client.go fix addMissingPort() (#1444)
* client.go Make addMissingPort() public
It's needed for those who creates the instance of the HostClient manually.
* client.go fix AddMissingPort()
Previously for IPv6 addresses the default port wasn't added.
The fix adding a test and optimization that should avoid itoa() call and reduce a memory usage
Diffstat (limited to 'client_test.go')
-rw-r--r-- | client_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/client_test.go b/client_test.go index 13da521..b5c0b7f 100644 --- a/client_test.go +++ b/client_test.go @@ -2971,3 +2971,63 @@ func TestHttpsRequestWithoutParsedURL(t *testing.T) { t.Fatal("https requests with IsTLS client must succeed") } } + +func Test_AddMissingPort(t *testing.T) { + type args struct { + addr string + isTLS bool + } + tests := []struct { + name string + args args + want string + }{ + { + args: args{"127.1", false}, // 127.1 is a short form of 127.0.0.1 + want: "127.1:80", + }, + { + args: args{"127.0.0.1", false}, + want: "127.0.0.1:80", + }, + { + args: args{"127.0.0.1", true}, + want: "127.0.0.1:443", + }, + { + args: args{"[::1]", false}, + want: "[::1]:80", + }, + { + args: args{"::1", false}, + want: "::1", // keep as is + }, + { + args: args{"[::1]", true}, + want: "[::1]:443", + }, + { + args: args{"127.0.0.1:8080", false}, + want: "127.0.0.1:8080", + }, + { + args: args{"127.0.0.1:8443", true}, + want: "127.0.0.1:8443", + }, + { + args: args{"[::1]:8080", false}, + want: "[::1]:8080", + }, + { + args: args{"[::1]:8443", true}, + want: "[::1]:8443", + }, + } + 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) + } + }) + } +} |