Use http.NewClient()

Fixes #413
This commit is contained in:
Yasuhiro Matsumoto 2026-02-18 23:27:49 +09:00
parent e61786cc6b
commit 4bfa10f9e7
No known key found for this signature in database
GPG key ID: F2EA90DF2C146D1E

View file

@ -36,7 +36,8 @@ func (p *BraveSearchProvider) Search(ctx context.Context, query string, count in
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
req.Header.Set("X-Subscription-Token", p.apiKey) 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) resp, err := client.Do(req)
if err != nil { if err != nil {
return "", fmt.Errorf("request failed: %w", err) 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) 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) resp, err := client.Do(req)
if err != nil { if err != nil {
return "", fmt.Errorf("request failed: %w", err) 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("Authorization", "Bearer "+p.apiKey)
req.Header.Set("User-Agent", userAgent) 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) resp, err := client.Do(req)
if err != nil { if err != nil {
return "", fmt.Errorf("request failed: %w", err) 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) req.Header.Set("User-Agent", userAgent)
client := &http.Client{ client := http.NewClient()
Timeout: 60 * time.Second, client.Timeout = 60 * time.Second
Transport: &http.Transport{ client.Transport.MaxIdleConns = 10
MaxIdleConns: 10, client.Transport.IdleConnTimeout = 30 * time.Second
IdleConnTimeout: 30 * time.Second, client.Transport.DisableCompression = false
DisableCompression: false, client.Transport.TLSHandshakeTimeout = 15 * time.Second
TLSHandshakeTimeout: 15 * time.Second, client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
}, if len(via) >= 5 {
CheckRedirect: func(req *http.Request, via []*http.Request) error { return fmt.Errorf("stopped after 5 redirects")
if len(via) >= 5 { }
return fmt.Errorf("stopped after 5 redirects") return nil
}
return nil
},
} }
resp, err := client.Do(req) resp, err := client.Do(req)