pub struct HttpProvider { /* private fields */ }Expand description
Provider that fetches rule-sets from HTTP/HTTPS URLs with local caching.
Implementations§
Source§impl HttpProvider
impl HttpProvider
Sourcepub fn new(
url: impl Into<String>,
cache_path: Option<PathBuf>,
format: impl Into<String>,
behavior: Option<String>,
) -> Self
pub fn new( url: impl Into<String>, cache_path: Option<PathBuf>, format: impl Into<String>, behavior: Option<String>, ) -> Self
Create a new HTTP provider.
url: Remote URL to fetch the rule-set from.cache_path: Optional local path to cache the fetched content.format: Rule-set format (“surge” or “clash”).behavior: Optional behavior hint (“domain”, “ipcidr”, “classical”, “domain-set”).
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set the HTTP request timeout.
Sourcepub async fn fetch(&self) -> Result<String, RulesError>
pub async fn fetch(&self) -> Result<String, RulesError>
Fetch the rule-set content from the remote URL.
Sourcepub async fn load(&self) -> Result<Vec<ParsedRule>, RulesError>
pub async fn load(&self) -> Result<Vec<ParsedRule>, RulesError>
Load the rule-set: try fetching from URL, fall back to cache on failure.
Sourcepub fn load_cached(&self) -> Result<Option<Vec<ParsedRule>>, RulesError>
pub fn load_cached(&self) -> Result<Option<Vec<ParsedRule>>, RulesError>
Load from cache only (for startup before first fetch).
Sourcepub fn cache_path(&self) -> Option<&Path>
pub fn cache_path(&self) -> Option<&Path>
Get the cache path of this provider.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpProvider
impl RefUnwindSafe for HttpProvider
impl Send for HttpProvider
impl Sync for HttpProvider
impl Unpin for HttpProvider
impl UnsafeUnpin for HttpProvider
impl UnwindSafe for HttpProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more