Skip to main content

parse_url

Function parse_url 

Source
pub fn parse_url(
    url: &str,
    etag: Option<&str>,
    modified: Option<&str>,
    user_agent: Option<&str>,
) -> Result<ParsedFeed>
Expand description

Parse feed from HTTP/HTTPS URL

Fetches the feed from the given URL and parses it. Supports conditional GET using ETag and Last-Modified headers for bandwidth-efficient caching.

§Arguments

  • url - HTTP or HTTPS URL to fetch
  • etag - Optional ETag from previous fetch for conditional GET
  • modified - Optional Last-Modified timestamp from previous fetch
  • user_agent - Optional custom User-Agent header

§Returns

Returns a ParsedFeed with HTTP metadata fields populated:

  • status: HTTP status code (200, 304, etc.)
  • href: Final URL after redirects
  • etag: ETag header value (for next request)
  • modified: Last-Modified header value (for next request)
  • headers: Full HTTP response headers

On 304 Not Modified, returns a feed with empty entries but status=304.

§Errors

Returns FeedError::Fetch with a http::FetchError if:

  • The URL is invalid (InvalidUrl) or targets a blocked address, including a redirect hop (BlockedAddress)
  • More than 10 redirects are followed (TooManyRedirects)
  • The HTTP status is 4xx or 5xx (Status; 304 is not an error)
  • The decompressed body exceeds max_feed_size_bytes (BodyTooLarge, 100 MB by default)
  • A conditional-request header value is invalid (InvalidHeader)
  • Any other network error occurs (Transport)

Other FeedError variants report a failure to parse the fetched body.

§Examples

use feedparser_rs::parse_url;

// First fetch
let feed = parse_url("https://example.com/feed.xml", None, None, None).unwrap();
println!("Title: {:?}", feed.feed.title);
println!("ETag: {:?}", feed.etag);

// Subsequent fetch with caching
let feed2 = parse_url(
    "https://example.com/feed.xml",
    feed.etag.as_deref(),
    feed.modified.as_deref(),
    None
).unwrap();

if feed2.status == Some(304) {
    println!("Feed not modified, use cached version");
}