Skip to main content

Fetcher

Struct Fetcher 

Source
pub struct Fetcher { /* private fields */ }
Expand description

Fetches from other servers. Cheap to share; one per process is enough.

Implementations§

Source§

impl Fetcher

Source

pub fn walk<'a>( &'a self, url: &Url, key: Option<&'a SenderKey>, limits: WalkLimits, ) -> Walk<'a>

Walk the collection at url, from its first page to its last, within limits, signing each fetch with key when one is given.

Source

pub fn walk_embedded<'a>( &'a self, collection: &Value, embedder: &str, key: Option<&'a SenderKey>, limits: WalkLimits, ) -> Walk<'a>

Walk a collection as the object embedder embeds it: its IRI, or the collection itself, perhaps with its first page in it, as a post embeds its replies.

What an object embeds is its own say, and the walk keeps to the object’s server: the collection, and every page of it, is fetched only from embedder’s origin. The items of a collection embedded in hand are the embedder’s claim, to be fetched from their own ids before they are trusted, as any item on another origin is.

Source§

impl Fetcher

Source

pub fn new(client: Client, first_scheme: Scheme) -> Self

A fetcher that signs in first_scheme until a host has accepted one.

Source

pub fn with_plain_http_webfinger(self, plain: bool) -> Self

Ask every WebFinger query over plain http rather than https, for tests whose servers cannot serve https. Off unless turned on.

Source

pub fn plain_http_webfinger(&self) -> bool

Whether WebFinger is asked over plain http.

Source

pub fn did_resolver(self, resolver: Arc<dyn DidResolver>) -> Self

Resolve DID methods other than did:key with resolver, when verifying portable objects.

Source

pub fn resolver(&self) -> Option<&dyn DidResolver>

The resolver portable objects are verified with, if any.

Source

pub fn client(&self) -> &Client

The client the fetcher sends through.

Source

pub async fn get( &self, url: &Url, accept: &str, key: Option<&SenderKey>, ) -> Result<Response, FetchError>

GET url, signed with key when given, following redirects.

The response’s url is where it was finally served from.

§Errors

When a URL is refused, a redirect cannot be followed, the request cannot be signed, or it fails. A response with any other status is Ok.

Source

pub async fn document( &self, url: &Url, key: Option<&SenderKey>, ) -> Result<Document, FetchError>

Fetch the ActivityPub document at url and establish it: served as ActivityPub with success, a JSON object, with an id on the origin it was finally served from, and naming no author on another origin.

§Errors

As Fetcher::get, and when the document is not established; a document whose id is elsewhere is FetchError::CrossOrigin, and one by an author elsewhere FetchError::ForeignAuthor.

Source

pub async fn unverified_json( &self, url: &Url, key: Option<&SenderKey>, ) -> Result<Option<Value>, FetchError>

Fetch the JSON at url without establishing it, as Mastodon’s fetch_resource_without_id_validation does: asked for as ActivityPub, and taken only from a 200 served as ActivityPub. What it says about itself is not checked, so it is only as trustworthy as the server it came from, whatever its id says: a caller that trusts it for anything more checks that itself.

None for a 2xx other than 200, for another content type, and for a body that is not JSON.

§Errors

As Fetcher::get, and FetchError::Status for a status other than success, so that the caller can tell a temporary failure from a permanent one.

Source

pub async fn lookup( &self, url: &Url, key: Option<&SenderKey>, ) -> Result<Document, FetchError>

Fetcher::document, and when the document’s id is on another origin, fetch that id instead, once: what comes back is trusted only if the owner of the id serves it.

§Errors

As Fetcher::document, for the second fetch when there is one.

A portable URL, ap or at a gateway, is fetched with Fetcher::portable instead.

Source§

impl Fetcher

Source

pub async fn portable( &self, uri: &ApUri, gateways: &[&str], key: Option<&SenderKey>, ) -> Result<Document, FetchError>

Fetch the portable object uri names from its gateways: the hints it carries, then gateways, in order, and no more than portable::MAX_GATEWAYS of them. The first document served as ActivityPub whose id is uri and whose proof by uri’s DID holds is returned; a gateway that fails any of that is passed over.

§Errors

FetchError::Portable, with why each gateway was passed over.

Source

pub async fn portable_collection( &self, owner: &Value, iri: &str, key: Option<&SenderKey>, ) -> Result<Document, FetchError>

Fetch a portable actor’s collection, its inbox, outbox, followers, following or liked, or a page of one, which FEP-ef61 lets a gateway serve without a proof. owner is the actor’s document, verified again here, which for did:key fetches nothing.

The collection is asked of the owner’s own gateways in turn, and no more than portable::MAX_GATEWAYS of them: one with no proof is taken because a gateway the owner lists served it, and from nowhere else, as FEP-ef61 asks. One with a proof is held to it, as any portable object is. A page with no proof has to name one of the owner’s collections as its partOf.

§Errors

FetchError::Invalid when owner is not an authentic portable actor or iri is not under its DID, and FetchError::Portable, with why each gateway was passed over, when none served it.

Source

pub async fn portable_media( &self, url: &str, digest: &str, gateways: &[&str], key: Option<&SenderKey>, ) -> Result<Media, FetchError>

Fetch the media a portable object refers to, and check it against digest, the digestMultibase the object gives it: FEP-ef61 asks for this whoever serves it. url is the object’s url for it: a hashlink is asked of gateways in turn, the gateways of the object’s owner, and no more than portable::MAX_GATEWAYS of them; any other URL is fetched as it is. What a response may hold is bounded by the client’s max_response_bytes.

§Errors

FetchError::Invalid when digest is not a SHA-256 multihash or url is a hashlink of another digest, and FetchError::Portable, with why each place asked was passed over, when none served it.

Source

pub async fn nodeinfo(&self, origin: &Url) -> Result<NodeInfo, FetchError>

Find what software the server at origin runs, and how it is used, from its NodeInfo: the links at /.well-known/nodeinfo, and the document of the newest schema they name. A link to another host is not followed, since a server answers only for itself.

§Errors

As Fetcher::get, FetchError::Status when either is not served, and FetchError::Invalid when either is not what NodeInfo says it is.

Source

pub async fn lookup_as<T: FromJson + ToJson>( &self, url: &Url, key: Option<&SenderKey>, ) -> Result<Typed<T>, FetchError>

Fetcher::lookup, and read what it found into T: an actor, a note, AnyObject for whatever it turns out to be. What reading lost is in Read::lost.

§Errors

As Fetcher::lookup, and FetchError::Read when the document is not a T.

Source§

impl Fetcher

Source

pub async fn webfinger(&self, address: &Address) -> Result<Found, FetchError>

Ask address’s host what it says of it, as Mastodon’s Webfinger does: at Address::webfinger_url, and, when that answers 404, at the query the host’s host-meta lrdd template names, whose own 404 is not followed further.

§Errors

As Fetcher::webfinger_at, and when host-meta does not answer 200 or names no query.

Source

pub async fn confirm( &self, address: &Address, actor: &str, ) -> Result<Resolved, ResolveError>

Confirm that address names actor, as confirm_with does, asking each host with Fetcher::webfinger.

§Errors

As confirm_with.

Source

pub async fn resolve(&self, address: &Address) -> Result<Resolved, ResolveError>

Resolve address to the handle its host says is canonical and the actor that names, as resolve_with does, asking each host with Fetcher::webfinger.

§Errors

As resolve_with.

Source

pub async fn webfinger_at(&self, url: &Url) -> Result<Found, FetchError>

Ask the WebFinger query url what it says, unsigned, as WebFinger is asked; Address::webfinger_url is the query for an address.

§Errors

When the request fails or is refused, the answer is not a 200, as Mastodon requires, or it is not a JSON object.

Trait Implementations§

Source§

impl Debug for Fetcher

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more