Skip to main content

Module feed

Module feed 

Source
Expand description

Feed fetch → parse → sanitize → store pipeline.

This is the module that turns a feed URL into rows in the store. It is deliberately conservative on three axes, because a feed reader ingests hostile, arbitrary web input:

  1. Politeness — fetches use a conditional GET (If-None-Match / If-Modified-Since from the stored ETag / Last-Modified), an identifiable crate::USER_AGENT, a request timeout, and a simple exponential backoff hint on error. A 304 Not Modified is a no-op: the feed is untouched apart from bumping its next-poll time.
  2. Safety — every entry’s HTML is run through ammonia before it is ever stored (and therefore before it is ever rendered). Scripts, event handlers, javascript: URLs, tracking pixels’ dangerous attributes, and other XSS vectors are stripped. Feeds carrying <script> is not hypothetical; treat all feed HTML as untrusted.
  3. Robustness — a malformed feed is logged and skipped, never a panic. One bad publisher must not take down the poller. All non-test paths use Result/anyhow; there are no unwrap/expects.

The normalized shape written to the store is the store’s own store::NewFeed / store::NewEntry; dedup is by feed-native GUID via store::insert_entries’s ON CONFLICT (feed_id, guid) upsert.

Enums§

FeedPrivacy
The privacy classification of a feed URL — the output of classify_feed_privacy.
PollOutcome
The outcome of polling a single feed. Lets the scheduler decide how to reschedule (and lets tests assert what happened) without inspecting the DB.

Functions§

backoff_for
Compute the backoff for the nth consecutive failure (1-based), clamped to [BACKOFF_MAX]. Exponential in the error count so transient blips retry soon while a durably-broken feed backs off toward daily.
build_client
Build a reqwest::Client configured for polite and safe feed fetching.
classify_feed_privacy
Classify whether a feed URL carries a secret credential in the URL itself.
discover_feed
Discover a feed URL from a site’s HTML via <link rel="alternate" type="application/rss+xml|atom+xml" href="…">.
poll_feed
Fetch, parse, sanitize, normalize, and store a single feed.