Improve fetcherUnverified
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) | ||
| 55 | 55 | 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 | 59 | return nil, "", "", err |
| 60 | 60 | } |
| 61 | 61 | |
| @@ -88,7 +88,15 @@ func (f *Fetcher) executeRequest(ctx context.Context, feedURL, etag, lastModifie | ||
| 88 | 88 | defer resp.Body.Close() |
| 89 | 89 | |
| 90 | 90 | 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 | |
| 92 | 100 | } |
| 93 | 101 | |
| 94 | 102 | 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, nil | 55 | 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, "", "", err | 59 | 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, 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 | ||
| 92 | } | 100 | } |
| 93 | 101 | ||
| 94 | if resp.StatusCode == http.StatusTooManyRequests { | 102 | if resp.StatusCode == http.StatusTooManyRequests { |