nandi/gleanpublic Fork 0
6be8ad9
Commits
Clone
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Tune HTTP client timeouts and use Cloudflare DNSUnverified

Julien Robert committed 2026-04-23T22:01:54+02:00 Browse files
6be8ad9 parent: 12e3cec
modified internal/feed/fetcher.go +2 -2
@@ -25,10 +25,10 @@ type Fetcher struct {
2525 func NewFetcher() *Fetcher {
2626 return &Fetcher{
2727 httpClient: &http.Client{
28- Timeout: 30 * time.Second,
28+ Timeout: 10 * time.Second,
2929 Transport: httpclient.NewTransport(),
3030 CheckRedirect: func(req *http.Request, via []*http.Request) error {
31- if len(via) >= 10 {
31+ if len(via) >= 5 {
3232 return fmt.Errorf("too many redirects")
3333 }
3434 return nil
@@ -25,10 +25,10 @@ type Fetcher struct {
25 func NewFetcher() *Fetcher {25 func NewFetcher() *Fetcher {
26 return &Fetcher{26 return &Fetcher{
27 httpClient: &http.Client{27 httpClient: &http.Client{
28- Timeout: 30 * time.Second,28+ Timeout: 10 * time.Second,
29 Transport: httpclient.NewTransport(),29 Transport: httpclient.NewTransport(),
30 CheckRedirect: func(req *http.Request, via []*http.Request) error {30 CheckRedirect: func(req *http.Request, via []*http.Request) error {
31- if len(via) >= 10 {31+ if len(via) >= 5 {
32 return fmt.Errorf("too many redirects")32 return fmt.Errorf("too many redirects")
33 }33 }
34 return nil34 return nil
modified internal/httpclient/httpclient.go +17 -6
@@ -16,16 +16,27 @@ const (
1616 AcceptHTML = "text/html,application/xhtml+xml;q=0.9"
1717 )
1818
19+var dnsResolver = &net.Resolver{
20+ PreferGo: true,
21+ Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
22+ d := net.Dialer{Timeout: 3 * time.Second}
23+ return d.DialContext(ctx, "udp", "1.1.1.1:53")
24+ },
25+}
26+
1927 func NewTransport() *http.Transport {
28+ dialer := &net.Dialer{
29+ Timeout: 5 * time.Second,
30+ KeepAlive: 15 * time.Second,
31+ FallbackDelay: 300 * time.Millisecond,
32+ Resolver: dnsResolver,
33+ }
34+
2035 return &http.Transport{
21- DialContext: (&net.Dialer{
22- Timeout: 10 * time.Second,
23- KeepAlive: 15 * time.Second,
24- FallbackDelay: 300 * time.Millisecond,
25- }).DialContext,
36+ DialContext: dialer.DialContext,
2637 MaxIdleConns: 50,
2738 IdleConnTimeout: 10 * time.Second,
28- TLSHandshakeTimeout: 10 * time.Second,
39+ TLSHandshakeTimeout: 5 * time.Second,
2940 ForceAttemptHTTP2: true,
3041 }
3142 }
@@ -16,16 +16,27 @@ const (
16 AcceptHTML = "text/html,application/xhtml+xml;q=0.9"16 AcceptHTML = "text/html,application/xhtml+xml;q=0.9"
17 )17 )
18 18
19+var dnsResolver = &net.Resolver{
20+ PreferGo: true,
21+ Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
22+ d := net.Dialer{Timeout: 3 * time.Second}
23+ return d.DialContext(ctx, "udp", "1.1.1.1:53")
24+ },
25+}
26+
19 func NewTransport() *http.Transport {27 func NewTransport() *http.Transport {
28+ dialer := &net.Dialer{
29+ Timeout: 5 * time.Second,
30+ KeepAlive: 15 * time.Second,
31+ FallbackDelay: 300 * time.Millisecond,
32+ Resolver: dnsResolver,
33+ }
34+
20 return &http.Transport{35 return &http.Transport{
21- DialContext: (&net.Dialer{36+ DialContext: dialer.DialContext,
22- Timeout: 10 * time.Second,
23- KeepAlive: 15 * time.Second,
24- FallbackDelay: 300 * time.Millisecond,
25- }).DialContext,
26 MaxIdleConns: 50,37 MaxIdleConns: 50,
27 IdleConnTimeout: 10 * time.Second,38 IdleConnTimeout: 10 * time.Second,
28- TLSHandshakeTimeout: 10 * time.Second,39+ TLSHandshakeTimeout: 5 * time.Second,
29 ForceAttemptHTTP2: true,40 ForceAttemptHTTP2: true,
30 }41 }
31 }42 }