Link header for better interoperability with Mastodon
One of my goals with this blog is to make it into a first class ActivityPub citizen. Today, I want to talk about how to make it so that Mastodon can lookup the blog post, when pasting the URL in its search box. I mostly write this down, to have the behavior documented somewhere.
The working solution
Basically, one inserts a link header of the following form
<link
href="https://mymath.rocks/objects/941090e8-de94-4095-89fa-5b314fe8e88c"
rel="alternate"
type="application/activity+json"
/>
into the <head>
section of the html document. Then Mastodon will look up the described json object. So entering https://blog.mymath.rocks/2023-03-15/BIN1_Moo_Authentication_and_Authoriation
into the search bar, will lead to the display of the object https://mymath.rocks/objects/941090e8-de94-4095-89fa-5b314fe8e88c
.
On a side note: The linked object is not the Activity, but the corresponding Article object.
What Mastodon does
When sends a GET request with Accept
-header application/activity+json
to the url of a mastodon post, i.e. the url you can copy from the address bar of your browser, Mastodon answers with the json corresponding to the object, and a link header of the form
link: <object_id; rel="alternate"; type="application/activity+json"
While this is also a working solution, it has the disadvantage that one needs to also validate the HTTP Signature for requests to the HTML page. As my blog is a completely independent server from the ActivityPub Server, this would lead to unnecessary duplication, thus this is not a solution that works for me.
Redirects
A naive approach would be to redirect the request from the HTML page to the object. Unfortunately, this doesn’t work with Mastodon as the HTTP Signatures do not get updated.