Skip to content

Commit e6b76e5

Browse files
authored
http: add comment for explaining the new http cli design and usage (#608)
1 parent 22e2d51 commit e6b76e5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/util/http/http.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type Client struct {
2121
}
2222

2323
func NewHTTPClient(getTLSConfig func() *tls.Config) *Client {
24+
// Since TLS config will hot reload, `TLSClientConfig` need update by `getTLSConfig()`
25+
// to obtain the latest TLS config.
2426
return &Client{
2527
cli: &http.Client{
2628
Transport: &http.Transport{TLSClientConfig: getTLSConfig()},
@@ -30,9 +32,14 @@ func NewHTTPClient(getTLSConfig func() *tls.Config) *Client {
3032
}
3133

3234
func (client *Client) Get(addr, path string, b backoff.BackOff, timeout time.Duration) ([]byte, error) {
35+
// http cli is shared in the server, copy cli is to avoid concurrently setting http request timeout
3336
cli := *client.cli
3437
cli.Timeout = timeout
3538
schema := "http"
39+
// If the `http.Client.Transport.TLSClientConfig` is nil, it will be set to not nil when first time
40+
// calling `http.Client.Get()`. So the url schema decided by `client.getTLSConfig()`, which indicate
41+
// TiProxy server contain TLS config or not.
42+
// See https://github.com/pingcap/tiproxy/issues/602
3643
if tlsConfig := client.getTLSConfig(); tlsConfig != nil {
3744
schema = "https"
3845
}

0 commit comments

Comments
 (0)