tls-client
tls-client copied to clipboard
[Bug]: roundtripper and client not reuse tcp connection
TLS client version
1.7.4
System information
...
Issue description
roundtripper does not support reusing tcp connection for subsequent requests
For each RoundTrip, a new connection opens and a handshake takes place, which greatly affects the speed of sending requests
Steps to reproduce / Code Sample
package main
import (
"context"
"io"
"log"
"net/url"
http "github.com/bogdanfinn/fhttp"
client "github.com/bogdanfinn/tls-client"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
options := []client.HttpClientOption{
//client.WithForceHttp1(),
client.WithRandomTLSExtensionOrder(),
client.WithTransportOptions(&client.TransportOptions{
MaxConnsPerHost: 1,
DisableCompression: true,
}),
}
client, _ := client.NewHttpClient(client.NewNoopLogger(), options...)
u, _ := url.ParseRequestURI("https://tls.peet.ws/api/tls")
for i := 0; i < 3; i++ {
request := &http.Request{
Method: "GET",
URL: u,
Header: http.Header{},
}
request = request.WithContext(ctx)
response, _ := client.Do(request)
log.Print(response)
body, _ := io.ReadAll(response.Body)
log.Printf("%s", string(body))
}
}
https://stackoverflow.com/questions/33238518/what-could-happen-if-i-dont-close-response-body