Files
gluetun/internal/healthcheck/client.go
T
Quentin McGaw d586793169 fix(all): increase global http client timeout to 35s and precise lower timeouts where needed
- Fix DNS blocklists slow downloads, fix #3102
- Leave 35s timeout for updaters
- Set timeouts to 1s for local calls
- Set timeouts to 5s for LAN VPN calls and small external calls
- Set timeouts to 10s external VPN API calls
2026-02-20 16:40:51 +00:00

47 lines
892 B
Go

package healthcheck
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"time"
)
var ErrHTTPStatusNotOK = errors.New("HTTP response status is not OK")
type Client struct {
httpClient *http.Client
}
func NewClient(httpClient *http.Client) *Client {
return &Client{
httpClient: httpClient,
}
}
func (c *Client) Check(ctx context.Context, url string) error {
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return err
}
response, err := c.httpClient.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
return nil
}
b, err := io.ReadAll(response.Body)
if err != nil {
return err
}
return fmt.Errorf("%w: %d %s: %s", ErrHTTPStatusNotOK,
response.StatusCode, response.Status, string(b))
}