Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: roundtripper and client not reuse tcp connection #112

Open
PandaWorker opened this issue Apr 26, 2024 · 1 comment
Open

[Bug]: roundtripper and client not reuse tcp connection #112

PandaWorker opened this issue Apr 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@PandaWorker
Copy link

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))
	}
}
@PandaWorker PandaWorker added the bug Something isn't working label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants