summaryrefslogtreecommitdiff
path: root/internal/api/s2s/webfinger/webfingerget.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-12-11 17:50:00 +0100
committerLibravatar GitHub <noreply@github.com>2021-12-11 17:50:00 +0100
commite2daf0f012a21928ceeba03e5754b5a2233f4016 (patch)
treee94cac357b3a2cc63db9adcb730ce3053bf0b970 /internal/api/s2s/webfinger/webfingerget.go
parentImplement Cobra CLI tooling, Viper config tooling (#336) (diff)
downloadgotosocial-e2daf0f012a21928ceeba03e5754b5a2233f4016.tar.xz
Add `Accept` header negotiation to relevant API endpoints (#337)
* start centralizing negotiation logic for API * swagger document nodeinfo endpoint * go fmt * document negotiate function * use content negotiation * tidy up negotiation logic * negotiate content throughout client api * swagger * remove attachment on Content * add accept header to test requests
Diffstat (limited to 'internal/api/s2s/webfinger/webfingerget.go')
-rw-r--r--internal/api/s2s/webfinger/webfingerget.go36
1 files changed, 32 insertions, 4 deletions
diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go
index b7f3c714d..6b0de69a9 100644
--- a/internal/api/s2s/webfinger/webfingerget.go
+++ b/internal/api/s2s/webfinger/webfingerget.go
@@ -27,26 +27,54 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
+ "github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
-// WebfingerGETRequest handles requests to, for example, https://example.org/.well-known/webfinger?resource=acct:some_user@example.org
+// WebfingerGETRequest swagger:operation GET /.well-known/webfinger webfingerGet
+//
+// Handles webfinger account lookup requests.
+//
+// For example, a GET to `https://goblin.technology/.well-known/webfinger?resource=acct:tobi@goblin.technology` would return:
+//
+// ```
+// {"subject":"acct:tobi@goblin.technology","aliases":["https://goblin.technology/users/tobi","https://goblin.technology/@tobi"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"https://goblin.technology/@tobi"},{"rel":"self","type":"application/activity+json","href":"https://goblin.technology/users/tobi"}]}
+// ```
+//
+// See: https://webfinger.net/
+//
+// ---
+// tags:
+// - webfinger
+//
+// produces:
+// - application/json
+//
+// responses:
+// '200':
+// schema:
+// "$ref": "#/definitions/wellKnownResponse"
func (m *Module) WebfingerGETRequest(c *gin.Context) {
l := logrus.WithFields(logrus.Fields{
"func": "WebfingerGETRequest",
"user-agent": c.Request.UserAgent(),
})
- q, set := c.GetQuery("resource")
- if !set || q == "" {
+ resourceQuery, set := c.GetQuery("resource")
+ if !set || resourceQuery == "" {
l.Debug("aborting request because no resource was set in query")
c.JSON(http.StatusBadRequest, gin.H{"error": "no 'resource' in request query"})
return
}
+ if _, err := api.NegotiateAccept(c, api.JSONAcceptHeaders...); err != nil {
+ c.JSON(http.StatusNotAcceptable, gin.H{"error": err.Error()})
+ return
+ }
+
// remove the acct: prefix if it's present
- trimAcct := strings.TrimPrefix(q, "acct:")
+ trimAcct := strings.TrimPrefix(resourceQuery, "acct:")
// remove the first @ in @whatever@example.org if it's present
namestring := strings.TrimPrefix(trimAcct, "@")