From 3f61299f726b90fe4e2fb221fa9b9bf9fa964b9b Mon Sep 17 00:00:00 2001 From: appleboy Date: Tue, 27 May 2025 12:52:19 +0000 Subject: [PATCH] refactor: refactor HTTP client setup to enhance configuration flexibility (#47) - Refactor HTTP client initialization to always create a custom http.Client - Move TLS config modification into the default HTTP client when insecure flag is set - Ensure the HTTP client is always included in client options Signed-off-by: appleboy Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/47 Co-authored-by: appleboy Co-committed-by: appleboy --- pkg/gitea/gitea.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/gitea/gitea.go b/pkg/gitea/gitea.go index e5e5b92..88dca3d 100644 --- a/pkg/gitea/gitea.go +++ b/pkg/gitea/gitea.go @@ -22,19 +22,20 @@ func Client() *gitea.Client { if client != nil { return } + + httpClient := &http.Client{ + Transport: http.DefaultTransport, + } + opts := []gitea.ClientOption{ gitea.SetToken(flag.Token), } if flag.Insecure { - httpClient := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, - }, - }, + httpClient.Transport.(*http.Transport).TLSClientConfig = &tls.Config{ + InsecureSkipVerify: true, } - opts = append(opts, gitea.SetHTTPClient(httpClient)) } + opts = append(opts, gitea.SetHTTPClient(httpClient)) if flag.Debug { opts = append(opts, gitea.SetDebugMode()) }