New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a HTTP header to make it possible to detect Mastodon #23939
Comments
Mastodon returns the “Server” header with the value “Mastodon” but I think it often gets stripped out or overwritten by nginx. |
There is a rel-alternate link of type If that would added to a (Eventually it could even be added to a 103 Early Hints response or HEAD requests to make it even more lightweight to figure out) As I noted in https://mastodon.social/@voxpelli/109959930023440575 it would be preferable if the solution is as independent as possible of Mastodon itself, so that other implementations of the same open protocols will also be supported. |
I'm not seeing the |
Yeah, the HTTP header is not there now, but the rel-alternate is in the HTML, see the parsed content eg here: https://pin13.net/mf2/?url=https%3A%2F%2Fmastodon.social%2F%40sindresorhus%2F109959846799782156 |
Some possible headers:
|
My use-case is to detect Mastodon specifically though, not any fediverse instance. So this feels like a separate issue. |
Could the existing "Server" header be overridden to read "Mastodon/xx.yy" with allowing for optional "Glitch (Mastodon/xx.yy; compatible)" similar to browser user agents? Might also be a case for .well-known/host-meta ( https://datatracker.ietf.org/doc/html/rfc6415 ) |
This should be a separate issue. |
I am developing a Chrome extension that could redirect to someone's personal Mastodon instance and came across this same issue. The usability issue of clicking on a Mastodon link and not being able to favorite or follow is quite frustrating, I think this would help. |
I was on my phone earlier, now home I could check more properly. There is a Link: <https://mastodon.social/users/sindresorhus/statuses/109959846799782156>; rel="alternate"; type="application/activity+json" Parse that using something like https://github.com/Frizlab/LinkHeaderParser and if the (This is about the same way that RSS discovery works (but Edit: This is where it is set in the code:
|
So, steps would be:
|
@voxpelli This is useful and should definitely be documented somewhere. However, it will not work for my specific use-case. My app redirects URLs and it needs to know exactly what it redirects so it can redirect to the correct thing. For example, a user may want to open links to a Mastodon instance and a PeerTube instance in different apps. Both are of type So my initial request still stands. |
@sinresorhus maybe you can you grab the list of domains from john mastodon's site: https://JoinMastodon.org Not a perfect solution, but it might get you part of the way there, and let you do the check without having to make a request from the server at all. |
@guest20 I'm already doing that. But that only works if I constantly keep the list up to date. I need a fallback for new and unknown servers, which is what this issue would solve. |
@sindresorhus good thinking :) My instances sends both It looks like it was introduced in ff229aa it was requested ... some time ago #141 |
Fetch the The document eg. has a One could also maybe do something like |
That's too slow. I already said I need a HEAD request. |
Pitch
Include a HTTP header in every response that indicates that the URL points to a Mastodon instance.
Motivation
I need to be able to quickly detect whether a link points to a Mastodon instance. I'm aware I could try fetching
https://[instance-url]/api/v1/instance
and deduce it from its content, but that's a bit fragile and also slow.If I instead could simply perform a HEAD request and check a header, it would be more reliable and faster.
My specific use-case:
I'm the author of a browser picker app called Velja. I want to add support for Mastodon. Meaning that when you click a Mastodon link outside of the browser, it will open with my app and my app will redirect it to a native app like Ivory. The problem is that I cannot know whether a link is a Mastodon link just by looking at the URL. I can have a list of popular Mastodon instances, but I can never cover them all, so I need a quick way to check whether a certain URL points to a Mastodon instance. It needs to be quick as it has to happen right after the user clicks a link and I don't want to keep them waiting.
I imagine there are other use-cases for this too. A link preview scraper could use this to quickly know whether to use a Mastodon scraper for the URL before starting to parse the content. A website that let users add social links could quickly check if the link is a Mastodon link and show the Mastodon icon.
The text was updated successfully, but these errors were encountered: