Skip to content

Commit

Permalink
fix: update Last-Modified if it changes in a 304 response
Browse files Browse the repository at this point in the history
When a server returns a 304 response with a strong validator, any other
stored fields must be updated if they are also present in the response.

This behaviour is described in RFC9111, sections 3.2 and 4.3.4.
  • Loading branch information
smlx authored and fguillot committed Oct 5, 2024
1 parent cb61023 commit 562a7b7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/reader/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
go integration.PushEntries(originalFeed, newEntries, userIntegrations)
}

// We update caching headers only if the feed has been modified,
// because some websites don't return the same headers when replying with a 304.
originalFeed.EtagHeader = responseHandler.ETag()
originalFeed.LastModifiedHeader = responseHandler.LastModified()

Expand All @@ -343,6 +341,11 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
slog.Int64("user_id", userID),
slog.Int64("feed_id", feedID),
)
// Last-Modified may be updated even if ETag is not. In this case, per
// RFC9111 sections 3.2 and 4.3.4, the stored response must be updated.
if responseHandler.LastModified() != "" {
originalFeed.LastModifiedHeader = responseHandler.LastModified()
}
}

originalFeed.ResetErrorCounter()
Expand Down

0 comments on commit 562a7b7

Please sign in to comment.