@@ -36,19 +36,28 @@ type clientOpts struct {
3636}
3737
3838type fasthttpClient struct {
39- client * fasthttp.Client
39+ client * fasthttp.HostClient
4040
41- headers * fasthttp.RequestHeader
42- url , method string
41+ headers * fasthttp.RequestHeader
42+ host , requestURI , method string
4343
4444 body * string
4545 bodProd bodyStreamProducer
4646}
4747
4848func newFastHTTPClient (opts * clientOpts ) client {
4949 c := new (fasthttpClient )
50- c .client = & fasthttp.Client {
51- MaxConnsPerHost : int (opts .maxConns ),
50+ u , err := url .Parse (opts .url )
51+ if err != nil {
52+ // opts.url guaranteed to be valid at this point
53+ panic (err )
54+ }
55+ c .host = u .Host
56+ c .requestURI = "/" + u .Path + "?" + u .RawQuery
57+ c .client = & fasthttp.HostClient {
58+ Addr : u .Host ,
59+ IsTLS : u .Scheme == "https" ,
60+ MaxConns : int (opts .maxConns ),
5261 ReadTimeout : opts .timeout ,
5362 WriteTimeout : opts .timeout ,
5463 DisableHeaderNamesNormalizing : true ,
@@ -58,7 +67,7 @@ func newFastHTTPClient(opts *clientOpts) client {
5867 ),
5968 }
6069 c .headers = headersToFastHTTPHeaders (opts .headers )
61- c .url , c . method , c .body = opts . url , opts .method , opts .body
70+ c .method , c .body = opts .method , opts .body
6271 c .bodProd = opts .bodProd
6372 return client (c )
6473}
@@ -72,8 +81,11 @@ func (c *fasthttpClient) do() (
7281 if c .headers != nil {
7382 c .headers .CopyTo (& req .Header )
7483 }
84+ if len (req .Header .Host ()) == 0 {
85+ req .Header .SetHost (c .host )
86+ }
7587 req .Header .SetMethod (c .method )
76- req .SetRequestURI (c .url )
88+ req .SetRequestURI (c .requestURI )
7789 if c .body != nil {
7890 req .SetBodyString (* c .body )
7991 } else {
0 commit comments