/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use md5::{Digest, Md5}; use url::{Host, Url};
pubtype UrlHash = [u8; 16];
/// Given a URL, extract the part of it that we want to use to identify it. pubfn url_hash_source(url: &str) -> Option<String> { // We currently use the final 2 components of the URL domain. const URL_COMPONENTS_TO_USE: usize = 2;
let url = Url::parse(url).ok()?; let domain = match url.host() {
Some(Host::Domain(d)) => d,
_ => return None,
}; // This will store indexes of `.` chars as we search backwards. letmut pos = domain.len(); for _ in0..URL_COMPONENTS_TO_USE { match domain[0..pos].rfind('.') {
Some(p) => pos = p, // The domain has less than 3 dots, return it all
None => return Some(domain.to_owned()),
}
}
Some(domain[pos + 1..].to_owned())
}
pubfn hash_url(url: &str) -> Option<UrlHash> {
url_hash_source(url).map(|hash_source| { letmut hasher = Md5::new();
hasher.update(hash_source); let result = hasher.finalize();
result.into()
})
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.