Skip to main content

Module fetch

Module fetch 

Source
Expand description

Fetching documents from other servers.

A fetch is a GET through the guarded Client, signed when the caller gives a key so that a server requiring authorized fetch answers it. The fetcher follows redirects itself: a signature covers the URL it was made for, so each hop is checked and signed again for where it goes, and a redirect from https to http is refused. A signed GET that is refused is tried once in the other scheme, as a delivery is, and the fetcher remembers which scheme each host accepted.

Fetcher::document returns a document only when it may be trusted as what it says it is: it came as ActivityPub, it is a JSON object with an id, and that id has the origin of the URL it was finally served from. Anyone can serve a document naming any id, and the only thing that vouches for an unsigned one is where it came from. Fetcher::lookup goes one step further, as Mastodon does: a document whose id is on another origin is fetched again from its id, once, and trusted only if the owner of the id serves it.

A portable object, whose id is an ap:// IRI, is never trusted from a fetch alone: its origin is a key, and only its proof vouches for it. Fetcher::portable asks its gateways for it and keeps the first copy whose proof holds; Fetcher::lookup sends a portable URL there.

Fetcher::walk goes through a collection’s items, a page at a time.

A web page that is not itself a document may name the document it shows in an alternate link: link_header_alternate and html_alternate find it, for an application resolving a URL someone pasted, as Mastodon’s FetchResourceService does.

Structs§

Document
A document, fetched and established as what it says it is.
Fetcher
Fetches from other servers. Cheap to share; one per process is enough.
Typed
A document fetched, established and read into a vocabulary type.
Walk
A walk through a collection’s items; see Fetcher::walk.
WalkLimits
How far a Walk goes.
WebLink
One entry of a Link header (RFC 8288).

Enums§

FetchError
Why a fetch did not produce a document.

Constants§

ACTIVITY_ACCEPT
What a fetch asks for: ActivityStreams, in either of its media types.
ACTIVITY_LINK_TYPES
The types an alternate link has to carry to name an ActivityPub object, in the order they are looked for: Mastodon’s FetchResourceService::ACTIVITY_STREAM_LINK_TYPES.
PORTABLE_ACCEPT
What a gateway is asked for, as FEP-ef61 has it.

Functions§

html_alternate
The target of the page’s first <link rel="alternate"> of an ACTIVITY_LINK_TYPES type, resolved against base, the URL the page was served from. Mastodon only meets absolute targets here, and resolving a relative one costs nothing.
is_activity_content_type
Whether content_type is ActivityStreams: application/activity+json, or application/ld+json with the ActivityStreams profile. Plain JSON is not enough; a server that lets its users upload files would otherwise serve documents in its own name that none of its actors wrote.
link_header_alternate
The target of the first Link header’s rel="alternate" entry of an ACTIVITY_LINK_TYPES type, as written.
parse_link_header
The entries of a Link header. A comma inside <…> or a quoted parameter value does not separate entries, and an entry without a <target> is passed over.