pub struct Fetcher { /* private fields */ }Expand description
Fetches from other servers. Cheap to share; one per process is enough.
Implementations§
Source§impl Fetcher
impl Fetcher
Sourcepub fn walk<'a>(
&'a self,
url: &Url,
key: Option<&'a SenderKey>,
limits: WalkLimits,
) -> Walk<'a>
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.
Sourcepub fn walk_embedded<'a>(
&'a self,
collection: &Value,
embedder: &str,
key: Option<&'a SenderKey>,
limits: WalkLimits,
) -> Walk<'a>
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
impl Fetcher
Sourcepub fn new(client: Client, first_scheme: Scheme) -> Self
pub fn new(client: Client, first_scheme: Scheme) -> Self
A fetcher that signs in first_scheme until a host has accepted one.
Sourcepub fn with_plain_http_webfinger(self, plain: bool) -> Self
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.
Sourcepub fn plain_http_webfinger(&self) -> bool
pub fn plain_http_webfinger(&self) -> bool
Whether WebFinger is asked over plain http.
Sourcepub fn did_resolver(self, resolver: Arc<dyn DidResolver>) -> Self
pub fn did_resolver(self, resolver: Arc<dyn DidResolver>) -> Self
Resolve DID methods other than did:key with resolver, when
verifying portable objects.
Sourcepub fn resolver(&self) -> Option<&dyn DidResolver>
pub fn resolver(&self) -> Option<&dyn DidResolver>
The resolver portable objects are verified with, if any.
Sourcepub async fn get(
&self,
url: &Url,
accept: &str,
key: Option<&SenderKey>,
) -> Result<Response, FetchError>
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.
Sourcepub async fn document(
&self,
url: &Url,
key: Option<&SenderKey>,
) -> Result<Document, FetchError>
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.
Sourcepub async fn unverified_json(
&self,
url: &Url,
key: Option<&SenderKey>,
) -> Result<Option<Value>, FetchError>
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.
Sourcepub async fn lookup(
&self,
url: &Url,
key: Option<&SenderKey>,
) -> Result<Document, FetchError>
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
impl Fetcher
Sourcepub async fn portable(
&self,
uri: &ApUri,
gateways: &[&str],
key: Option<&SenderKey>,
) -> Result<Document, FetchError>
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.
Sourcepub async fn portable_collection(
&self,
owner: &Value,
iri: &str,
key: Option<&SenderKey>,
) -> Result<Document, FetchError>
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.
Sourcepub async fn portable_media(
&self,
url: &str,
digest: &str,
gateways: &[&str],
key: Option<&SenderKey>,
) -> Result<Media, FetchError>
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.
Sourcepub async fn nodeinfo(&self, origin: &Url) -> Result<NodeInfo, FetchError>
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.
Sourcepub async fn lookup_as<T: FromJson + ToJson>(
&self,
url: &Url,
key: Option<&SenderKey>,
) -> Result<Typed<T>, FetchError>
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
impl Fetcher
Sourcepub async fn webfinger(&self, address: &Address) -> Result<Found, FetchError>
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.
Sourcepub async fn confirm(
&self,
address: &Address,
actor: &str,
) -> Result<Resolved, ResolveError>
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.
Sourcepub async fn resolve(&self, address: &Address) -> Result<Resolved, ResolveError>
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.
Sourcepub async fn webfinger_at(&self, url: &Url) -> Result<Found, FetchError>
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.