Skip to main content

Rule

Enum Rule 

Source
pub enum Rule {
    Block {
        pattern: UrlPattern,
    },
    Redirect {
        from: UrlPattern,
        to: String,
    },
    Respond {
        pattern: UrlPattern,
        status: u16,
        headers: Vec<(String, String)>,
        body: Vec<u8>,
    },
    Modify {
        pattern: UrlPattern,
        modify: Arc<dyn Fn(&RequestInfo) -> RequestOverrides + Send + Sync>,
    },
    ModifyResponse {
        pattern: UrlPattern,
        modify: Arc<dyn Fn(&ResponseInfo) -> ResponseOverrides + Send + Sync>,
    },
    BlockHosts {
        matcher: Arc<HostMatcher>,
    },
}
Expand description

A single interception rule.

Each variant carries its own UrlPattern, so different rules in the same InterceptBuilder can match disjoint URL sets. Rules are evaluated in registration order — earlier rules shadow later ones for overlapping patterns.

Variants§

§

Block

Abort matching requests with Fetch.failRequest (errorReason: "BlockedByClient").

Fields

§pattern: UrlPattern

URL pattern matched against Fetch.requestPaused.request.url.

§

Redirect

Redirect matching requests to to via Fetch.continueRequest { url }.

Fields

§from: UrlPattern

URL pattern matched against the incoming request URL.

§to: String

Absolute target URL substituted into the continued request.

§

Respond

Serve a synthesized response with Fetch.fulfillRequest.

Fields

§pattern: UrlPattern

URL pattern matched against the incoming request URL.

§status: u16

HTTP status code returned to the page (responseCode).

§headers: Vec<(String, String)>

Response headers as (name, value) pairs.

§body: Vec<u8>

Raw response body bytes (base64-encoded on the wire by the actor).

§

Modify

Rewrite the outgoing request per-field via a user closure, then continue. The closure receives the live RequestInfo and returns the RequestOverrides to apply.

Fields

§pattern: UrlPattern

URL pattern matched against the incoming request URL.

§modify: Arc<dyn Fn(&RequestInfo) -> RequestOverrides + Send + Sync>

Closure invoked per matching request to produce overrides.

Wrapped in Arc so the actor can cheaply share the closure across the rule list without forcing the rule itself to be Clone or Send-by-value.

§

ModifyResponse

Rewrite an upstream response’s status/headers per a user closure, then continue with Fetch.continueResponse (keeping Chrome’s body). Only fires at the Response stage — the closure receives the live ResponseInfo and returns the ResponseOverrides to apply. A rule of this kind that matches at the Request stage is a no-op (there is no response yet).

Fields

§pattern: UrlPattern

URL pattern matched against the incoming request URL.

§modify: Arc<dyn Fn(&ResponseInfo) -> ResponseOverrides + Send + Sync>

Closure invoked per matching response to produce overrides.

Wrapped in Arc for the same cheap-share reason as Modify.

§

BlockHosts

Abort requests whose host is in a HostMatcher with Fetch.failRequest { errorReason: "BlockedByClient" } — the same net::ERR_BLOCKED_BY_CLIENT a real adblocker / Brave raises.

Unlike Block, which globs the full URL, this matches host-set membership (exact + parent-domain suffix on dot boundaries), so a curated list of thousands of hosts is one O(1) set lookup per request rather than N glob comparisons. Powers the tracker blocklist.

Fields

§matcher: Arc<HostMatcher>

Shared host set; cheap to clone across tabs/rules.

Implementations§

Source§

impl Rule

Source

pub fn matches(&self, url: &str) -> bool

Test whether this rule’s pattern matches url.

Delegates to the embedded UrlPattern::matches; the field selector (pattern, from) varies per variant but the semantics are identical — a CDP-style wildcard match against the full request URL.

Trait Implementations§

Source§

impl Debug for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Rule

§

impl !UnwindSafe for Rule

§

impl Freeze for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnsafeUnpin for Rule

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more