From a312238e7909c6451e608a91c326ad250dda875c Mon Sep 17 00:00:00 2001 From: Daenney Date: Thu, 9 Mar 2023 18:55:45 +0100 Subject: [feature] Provide .well-known/host-meta endpoint (#1604) * [feature] Provide .well-known/host-meta endpoint This adds the host-meta endpoint as Mastodon clients use this to discover the API domain to use when the host and account domains aren't the same. * Address review comments --- internal/processing/fedi/wellknown.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'internal/processing/fedi') diff --git a/internal/processing/fedi/wellknown.go b/internal/processing/fedi/wellknown.go index 6f113ac5d..7be75649b 100644 --- a/internal/processing/fedi/wellknown.go +++ b/internal/processing/fedi/wellknown.go @@ -28,6 +28,10 @@ import ( ) const ( + hostMetaXMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0" + hostMetaRel = "lrdd" + hostMetaType = "application/xrd+xml" + hostMetaTemplate = ".well-known/webfinger?resource={uri}" nodeInfoVersion = "2.0" nodeInfoSoftwareName = "gotosocial" nodeInfoRel = "http://nodeinfo.diaspora.software/ns/schema/" + nodeInfoVersion @@ -96,6 +100,22 @@ func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserr }, nil } +// HostMetaGet returns a host-meta struct in response to a host-meta request. +func (p *Processor) HostMetaGet() *apimodel.HostMeta { + protocol := config.GetProtocol() + host := config.GetHost() + return &apimodel.HostMeta{ + XMLNS: hostMetaXMLNS, + Link: []apimodel.Link{ + { + Rel: hostMetaRel, + Type: hostMetaType, + Template: fmt.Sprintf("%s://%s/%s", protocol, host, hostMetaTemplate), + }, + }, + } +} + // WebfingerGet handles the GET for a webfinger resource. Most commonly, it will be used for returning account lookups. func (p *Processor) WebfingerGet(ctx context.Context, requestedUsername string) (*apimodel.WellKnownResponse, gtserror.WithCode) { // Get the local account the request is referring to. -- cgit v1.2.3