pub struct Options {
pub default_protocol: Protocol,
pub custom_protocols: Vec<String>,
pub normalize_protocol: bool,
pub force_http: bool,
pub force_https: bool,
pub strip_authentication: bool,
pub strip_hash: bool,
pub strip_protocol: bool,
pub strip_text_fragment: bool,
pub strip_www: bool,
pub remove_query_parameters: RemoveQueryParameters,
pub keep_query_parameters: Option<Vec<QueryFilter>>,
pub remove_trailing_slash: bool,
pub remove_single_slash: bool,
pub remove_directory_index: RemoveDirectoryIndex,
pub remove_explicit_port: bool,
pub sort_query_parameters: bool,
pub empty_query_value: EmptyQueryValue,
pub remove_path: bool,
pub transform_path: Option<TransformPathFn>,
}
pub type TransformPathFn = Box<dyn Fn(Vec<String>) -> Vec<String>>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Protocol {
Http,
Https,
}
pub enum QueryFilter {
Exact(String),
Predicate(Box<dyn Fn(&str) -> bool>),
}
impl QueryFilter {
pub fn matches(&self, name: &str) -> bool {
match self {
QueryFilter::Exact(s) => s == name,
QueryFilter::Predicate(f) => f(name),
}
}
}
pub enum RemoveQueryParameters {
None,
All,
List(Vec<QueryFilter>),
}
pub enum RemoveDirectoryIndex {
None,
Default,
List(Vec<QueryFilter>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EmptyQueryValue {
Preserve,
Always,
Never,
}
impl Default for Options {
fn default() -> Self {
Options {
default_protocol: Protocol::Http,
custom_protocols: vec![],
normalize_protocol: true,
force_http: false,
force_https: false,
strip_authentication: true,
strip_hash: false,
strip_protocol: false,
strip_text_fragment: true,
strip_www: true,
remove_query_parameters: RemoveQueryParameters::List(vec![QueryFilter::Predicate(
Box::new(|key: &str| {
key.len() >= 4
&& key.is_char_boundary(4)
&& key[..4].eq_ignore_ascii_case("utm_")
}),
)]),
keep_query_parameters: None,
remove_trailing_slash: true,
remove_single_slash: true,
remove_directory_index: RemoveDirectoryIndex::None,
remove_explicit_port: false,
sort_query_parameters: true,
empty_query_value: EmptyQueryValue::Preserve,
remove_path: false,
transform_path: None,
}
}
}