mirror of
https://github.com/gofiber/fiber.git
synced 2025-04-27 13:14:31 +00:00
optimize: use fasthttp.AddMissingPort (#2268)
This commit is contained in:
parent
affa759477
commit
2e3f73cb4d
16
client.go
16
client.go
@ -8,11 +8,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -202,7 +200,7 @@ func (a *Agent) Parse() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a.HostClient = &fasthttp.HostClient{
|
a.HostClient = &fasthttp.HostClient{
|
||||||
Addr: addMissingPort(string(uri.Host()), isTLS),
|
Addr: fasthttp.AddMissingPort(string(uri.Host()), isTLS),
|
||||||
Name: name,
|
Name: name,
|
||||||
NoDefaultUserAgentHeader: a.NoDefaultUserAgentHeader,
|
NoDefaultUserAgentHeader: a.NoDefaultUserAgentHeader,
|
||||||
IsTLS: isTLS,
|
IsTLS: isTLS,
|
||||||
@ -211,18 +209,6 @@ func (a *Agent) Parse() error {
|
|||||||
return nil
|
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 **************************/
|
/************************** Header Setting **************************/
|
||||||
|
|
||||||
// Set sets the given 'key: value' header.
|
// Set sets the given 'key: value' header.
|
||||||
|
@ -1134,11 +1134,6 @@ func Test_Client_Agent_Parse(t *testing.T) {
|
|||||||
utils.AssertEqual(t, nil, a.Parse())
|
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) {
|
func testAgent(t *testing.T, handler Handler, wrapAgent func(agent *Agent), excepted string, count ...int) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user