Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

814 B
Raw Blame
use psl_types::{List as Psl, Suffix};

/// Public-suffix lookup needed by cookie Domain-attribute validation.
///
/// This object-safe boundary lets browser embedders provide either a static
/// generated table or another implementation of [`psl_types::List`].
pub trait CookiePublicSuffixList: std::fmt::Debug + Send + Sync {
    /// Returns whether `domain` exactly matches an explicitly listed suffix.
    fn is_public_suffix(&self, domain: &[u8]) -> bool;
}

impl<T> CookiePublicSuffixList for T
where
    T: Psl + std::fmt::Debug + Send + Sync,
{
    fn is_public_suffix(&self, domain: &[u8]) -> bool {
        self.suffix(domain)
            // The implicit wildcard must not reject arbitrary top-level names.
            .filter(Suffix::is_known)
            .is_some_and(|suffix| suffix == domain)
    }
}