referer-parser-rs
Rust implementation of snowplow-referer-parser. Identifies the source of a HTTP referer URL (search engine, social network, webmail, etc.) and extracts the search term when available.
Usage
Download the referers.yml database, then:
use Parser;
use Url;
let parser = new.unwrap;
let url = parse.unwrap;
if let Some = parser.lookup
Design
- The YAML database is loaded once into a flat
Vecof entries, with aHashMapmapping each domain (or domain/path) key to an entry index. lookupreturns anEntrythat borrows from both theParserand the inputUrl-- no heap allocation unless percent-decoding is needed for the search term.- Domain resolution walks subdomains (
www.google.fr->google.fr) and path prefixes (/webmail/fr_FR->/webmail), preferring path-qualified matches over domain-only matches.