Trait activitypub_federation::config::UrlVerifier

source ·
pub trait UrlVerifier: DynClone + Send {
    // Required method
    fn verify<'life0, 'life1, 'async_trait>(
        &'life0 self,
        url: &'life1 Url
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Handler for validating URLs.

This is used for implementing domain blocklists and similar functionality. It is called with the ID of newly received activities, when fetching remote data from a given URL and before sending an activity to a given inbox URL. If processing for this domain/URL should be aborted, return an error. In case of Ok(()), processing continues.

#[derive(Clone)]
struct Verifier {
    db_connection: DatabaseConnection,
}

#[async_trait]
impl UrlVerifier for Verifier {
    async fn verify(&self, url: &Url) -> Result<(), Error> {
        let blocklist = get_blocklist(&self.db_connection).await;
        let domain = url.domain().unwrap().to_string();
        if blocklist.contains(&domain) {
            Err(Error::Other("Domain is blocked".into()))
        } else {
            Ok(())
        }
    }
}

Required Methods§

source

fn verify<'life0, 'life1, 'async_trait>( &'life0 self, url: &'life1 Url ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Should return Ok iff the given url is valid for processing.

Implementors§