url_cleaner_engine/tutorial/
cleaner.rs

1//! # [`Cleaner`]
2//!
3//! A [`Cleaner`] is the bulk configuration unit for URL Cleaner Engine. It contains all the logic for how to clean URLs as well as documentation about itself.
4//!
5//! The following cleaner always removes the `utm_source` query parameter and, if the `https_upgrade` flag is enabled, upgrades HTTP URLs to HTTPS.
6//!
7//! ```Json
8//! {
9//!   "docs": {
10//!     "name": "Example cleaner",
11//!     "description": [
12//!       "An example cleaner"
13//!     ],
14//!     "flags": {
15//!       "https_upgrade": "Upgrade HTTP URLs to HTTPS"
16//!     }
17//!   },
18//!   "actions": [
19//!     {"RemoveQueryParam": "utm_source"},
20//!     {"If": {
21//!       "if": {"All": [
22//!         {"FlagIsSet": "https_upgrade"},
23//!         {"SchemeIs": "http"}
24//!       ]},
25//!       "then": {"SetScheme": "https"}
26//!     }}
27//!   ]
28//! }
29//! ```
30//!
31//! The `docs` field contains the [`CleanerDocs`]. It's optional but polite to add.
32//!
33//! The omitted [`params`] field contains the [`Params`] used to store configuration data.
34//!
35//! The omitted [`commons`] field contains the [`Commons`] used to store components used in multiple places.
36//!
37//! The [`actions`] field contains a list of [`Action`]s to do. The first action, written as [`RemoveQueryParam`](Action::RemoveQueryParam) removes any "utm_source" query param found in the URL.
38//!
39//! The second action, the [`If`](Action::If) action, applies the action in its [`then`](Action::If::then) field if and only if the condition in its [`if`](Action::If::if) field is "satisfied".
40//! In this case, the condition is satisfied if the "https_upgrade" flag is set and the URL's scheme is "http".
41//!
42//! Unlike AdGuard/uBlock Origin filters, URL Cleaner actions are applied in order of declaration.
43//! This has the benefit of letting you build far more complex operations out of far simpler building blocks, but has the downside of being very easy to write slow cleaners.
44
45pub(crate) use super::*;
46
47pub mod params;
48pub(crate) use params::*;
49#[cfg(feature = "default-cleaner")]
50pub mod default_cleaner;
51#[cfg(feature = "default-cleaner")]
52pub(crate) use default_cleaner::*;
53pub mod commons;
54pub(crate) use commons::*;
55pub mod string_modification;
56pub(crate) use string_modification::*;
57pub mod string_source;
58pub(crate) use string_source::*;
59pub mod action;
60pub(crate) use action::*;
61pub mod control_flow;
62pub(crate) use control_flow::*;
63pub mod glue;
64pub(crate) use glue::*;
65pub mod url_part;
66pub(crate) use url_part::*;
67pub mod set;
68pub(crate) use set::*;