nandi/gleanpublic Fork 0
fea0e33
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.

Improve fetcherUnverified

Julien Robert committed 2026-04-23T21:36:21+02:00 Browse files
fea0e33 parent: 681840f
modified internal/feed/fetcher.go +10 -2
@@ -55,7 +55,7 @@ func (f *Fetcher) Fetch(ctx context.Context, feedURL, etag, lastModified string)
5555 return result, newEtag, newLastModified, nil
5656 }
5757
58- if resp == nil || !httpclient.IsRetryable(resp.StatusCode) {
58+ if resp != nil && !httpclient.IsRetryable(resp.StatusCode) {
5959 return nil, "", "", err
6060 }
6161
@@ -88,7 +88,15 @@ func (f *Fetcher) executeRequest(ctx context.Context, feedURL, etag, lastModifie
8888 defer resp.Body.Close()
8989
9090 if resp.StatusCode == http.StatusNotModified {
91- return nil, "", "", resp, nil
91+ newEtag := resp.Header.Get("ETag")
92+ if newEtag == "" {
93+ newEtag = etag
94+ }
95+ newLastModified := resp.Header.Get("Last-Modified")
96+ if newLastModified == "" {
97+ newLastModified = lastModified
98+ }
99+ return nil, newEtag, newLastModified, resp, nil
92100 }
93101
94102 if resp.StatusCode == http.StatusTooManyRequests {
@@ -55,7 +55,7 @@ func (f *Fetcher) Fetch(ctx context.Context, feedURL, etag, lastModified string)
55 return result, newEtag, newLastModified, nil55 return result, newEtag, newLastModified, nil
56 }56 }
57 57
58- if resp == nil || !httpclient.IsRetryable(resp.StatusCode) {58+ if resp != nil && !httpclient.IsRetryable(resp.StatusCode) {
59 return nil, "", "", err59 return nil, "", "", err
60 }60 }
61 61
@@ -88,7 +88,15 @@ func (f *Fetcher) executeRequest(ctx context.Context, feedURL, etag, lastModifie
88 defer resp.Body.Close()88 defer resp.Body.Close()
89 89
90 if resp.StatusCode == http.StatusNotModified {90 if resp.StatusCode == http.StatusNotModified {
91- return nil, "", "", resp, nil91+ newEtag := resp.Header.Get("ETag")
92+ if newEtag == "" {
93+ newEtag = etag
94+ }
95+ newLastModified := resp.Header.Get("Last-Modified")
96+ if newLastModified == "" {
97+ newLastModified = lastModified
98+ }
99+ return nil, newEtag, newLastModified, resp, nil
92 }100 }
93 101
94 if resp.StatusCode == http.StatusTooManyRequests {102 if resp.StatusCode == http.StatusTooManyRequests {