From 4bfa10f9e7b7e9380a3eef78d50b3c8290cb8a04 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 18 Feb 2026 23:27:49 +0900 Subject: [PATCH] Use http.NewClient() Fixes #413 --- pkg/tools/web.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/tools/web.go b/pkg/tools/web.go index 6a6d40ecf..1adc9629e 100644 --- a/pkg/tools/web.go +++ b/pkg/tools/web.go @@ -36,7 +36,8 @@ func (p *BraveSearchProvider) Search(ctx context.Context, query string, count in req.Header.Set("Accept", "application/json") req.Header.Set("X-Subscription-Token", p.apiKey) - client := &http.Client{Timeout: 10 * time.Second} + client := http.NewClient() + client.Timeout = 10 * time.Second resp, err := client.Do(req) if err != nil { return "", fmt.Errorf("request failed: %w", err) @@ -96,7 +97,8 @@ func (p *DuckDuckGoSearchProvider) Search(ctx context.Context, query string, cou req.Header.Set("User-Agent", userAgent) - client := &http.Client{Timeout: 10 * time.Second} + client := http.NewClient() + client.Timeout = 10 * time.Second resp, err := client.Do(req) if err != nil { return "", fmt.Errorf("request failed: %w", err) @@ -206,7 +208,8 @@ func (p *PerplexitySearchProvider) Search(ctx context.Context, query string, cou req.Header.Set("Authorization", "Bearer "+p.apiKey) req.Header.Set("User-Agent", userAgent) - client := &http.Client{Timeout: 30 * time.Second} + client := http.NewClient() + client.Timeout = 30 * time.Second resp, err := client.Do(req) if err != nil { return "", fmt.Errorf("request failed: %w", err) @@ -410,20 +413,17 @@ func (t *WebFetchTool) Execute(ctx context.Context, args map[string]interface{}) req.Header.Set("User-Agent", userAgent) - client := &http.Client{ - Timeout: 60 * time.Second, - Transport: &http.Transport{ - MaxIdleConns: 10, - IdleConnTimeout: 30 * time.Second, - DisableCompression: false, - TLSHandshakeTimeout: 15 * time.Second, - }, - CheckRedirect: func(req *http.Request, via []*http.Request) error { - if len(via) >= 5 { - return fmt.Errorf("stopped after 5 redirects") - } - return nil - }, + client := http.NewClient() + client.Timeout = 60 * time.Second + client.Transport.MaxIdleConns = 10 + client.Transport.IdleConnTimeout = 30 * time.Second + client.Transport.DisableCompression = false + client.Transport.TLSHandshakeTimeout = 15 * time.Second + client.CheckRedirect = func(req *http.Request, via []*http.Request) error { + if len(via) >= 5 { + return fmt.Errorf("stopped after 5 redirects") + } + return nil } resp, err := client.Do(req)