pub struct FeedHttpClient { /* private fields */ }Expand description
HTTP client for fetching feeds
Implementations§
Source§impl FeedHttpClient
impl FeedHttpClient
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a new HTTP client with default settings
Default settings:
- 30 second timeout
- Gzip, deflate, and brotli compression enabled
- Maximum 10 redirects, each re-validated against the SSRF checks
- DNS resolution re-validated against the SSRF checks to close DNS-rebinding gaps between validation and connect time
- No system/environment proxy (
HTTP_PROXY,HTTPS_PROXY,ALL_PROXY) is honored: a proxy connects through a hostname that is resolved by the proxy itself, not by the DNS-rebinding-safe resolver above, which would silently defeat that protection - Custom User-Agent
- Response bodies capped at
ParserLimits::max_feed_size_bytes’s default (seeSelf::with_max_body_size)
§Errors
Returns FeedError::Fetch if the underlying HTTP client cannot be created.
Sourcepub fn with_user_agent(self, agent: String) -> Self
pub fn with_user_agent(self, agent: String) -> Self
Sets a custom User-Agent header
§Security
User-Agent is truncated to 512 bytes to prevent header injection attacks.
Sourcepub const fn with_timeout(self, timeout: Duration) -> Self
pub const fn with_timeout(self, timeout: Duration) -> Self
Sets the per-request timeout applied to every Self::get call.
The value is a total deadline covering connection, all redirect hops,
and the full response body — not a per-hop timeout. Duration::ZERO
means “time out immediately”, not “disable the timeout”; this API has
no way to disable it entirely. Values above one hour are clamped to
one hour: reqwest’s blocking wait computes its deadline as
Instant::now() + timeout without an overflow check, so passing
Duration::MAX (or another value near the Instant range limit)
would otherwise panic instead of erroring.
Sourcepub const fn with_max_body_size(self, max_bytes: usize) -> Self
pub const fn with_max_body_size(self, max_bytes: usize) -> Self
Caps the size of the response body read by Self::get.
The limit applies to the decompressed bytes, so a small compressed response
cannot expand without bound. At most max_bytes + 1 bytes are read; a longer
body makes Self::get return FetchError::BodyTooLarge, except for a 4xx or 5xx
response, whose body is truncated to the limit so that the status survives.
usize::MAX removes the bound.
§Examples
use feedparser_rs::FeedHttpClient;
let client = FeedHttpClient::new()?.with_max_body_size(1024 * 1024);Sourcepub fn get(
&self,
url: &str,
etag: Option<&str>,
modified: Option<&str>,
extra_headers: Option<&HeaderMap>,
) -> Result<FeedHttpResponse>
pub fn get( &self, url: &str, etag: Option<&str>, modified: Option<&str>, extra_headers: Option<&HeaderMap>, ) -> Result<FeedHttpResponse>
Fetches a feed from the given URL
Supports conditional GET with ETag and Last-Modified headers.
§Arguments
url- HTTP/HTTPS URL to fetchetag- OptionalETagfrom previous fetchmodified- OptionalLast-Modifiedfrom previous fetchextra_headers- Additional custom headers
§Errors
Returns FeedError::Fetch with FetchError::InvalidUrl or
FetchError::BlockedAddress for a rejected URL or redirect hop,
FetchError::TooManyRedirects, FetchError::InvalidHeader,
FetchError::BodyTooLarge for the body of a response below status 400
that exceeds the limit set by Self::with_max_body_size, and
FetchError::Transport for any other failure. A 4xx or 5xx status is not
an error here: the response is returned with its status.