summaryrefslogtreecommitdiff
path: root/internal/api/wellknown
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/wellknown')
-rw-r--r--internal/api/wellknown/hostmeta/hostmetaget.go27
-rw-r--r--internal/api/wellknown/nodeinfo/nodeinfoget.go9
-rw-r--r--internal/api/wellknown/webfinger/webfingerget.go18
3 files changed, 24 insertions, 30 deletions
diff --git a/internal/api/wellknown/hostmeta/hostmetaget.go b/internal/api/wellknown/hostmeta/hostmetaget.go
index c74a2e246..131e2ac58 100644
--- a/internal/api/wellknown/hostmeta/hostmetaget.go
+++ b/internal/api/wellknown/hostmeta/hostmetaget.go
@@ -18,8 +18,6 @@
package hostmeta
import (
- "bytes"
- "encoding/xml"
"net/http"
"github.com/gin-gonic/gin"
@@ -52,21 +50,12 @@ func (m *Module) HostMetaGETHandler(c *gin.Context) {
hostMeta := m.processor.Fedi().HostMetaGet()
- // this setup with a separate buffer we encode into is used because
- // xml.Marshal does not emit xml.Header by itself
- var buf bytes.Buffer
-
- // Preallocate buffer of reasonable length.
- buf.Grow(len(xml.Header) + 64)
-
- // No need to check for error on write to buffer.
- _, _ = buf.WriteString(xml.Header)
-
- // Encode host-meta as XML to in-memory buffer.
- if err := xml.NewEncoder(&buf).Encode(hostMeta); err != nil {
- apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
- return
- }
-
- c.Data(http.StatusOK, HostMetaContentType, buf.Bytes())
+ // Encode XML HTTP response.
+ apiutil.EncodeXMLResponse(
+ c.Writer,
+ c.Request,
+ http.StatusOK,
+ HostMetaContentType,
+ hostMeta,
+ )
}
diff --git a/internal/api/wellknown/nodeinfo/nodeinfoget.go b/internal/api/wellknown/nodeinfo/nodeinfoget.go
index 3cbb29650..c458f131e 100644
--- a/internal/api/wellknown/nodeinfo/nodeinfoget.go
+++ b/internal/api/wellknown/nodeinfo/nodeinfoget.go
@@ -55,5 +55,12 @@ func (m *Module) NodeInfoWellKnownGETHandler(c *gin.Context) {
return
}
- c.JSON(http.StatusOK, resp)
+ // Encode JSON HTTP response.
+ apiutil.EncodeJSONResponse(
+ c.Writer,
+ c.Request,
+ http.StatusOK,
+ apiutil.AppJSON,
+ resp,
+ )
}
diff --git a/internal/api/wellknown/webfinger/webfingerget.go b/internal/api/wellknown/webfinger/webfingerget.go
index 02f366ea6..74cb8fefe 100644
--- a/internal/api/wellknown/webfinger/webfingerget.go
+++ b/internal/api/wellknown/webfinger/webfingerget.go
@@ -18,7 +18,6 @@
package webfinger
import (
- "encoding/json"
"errors"
"fmt"
"net/http"
@@ -87,13 +86,12 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) {
return
}
- b, err := json.Marshal(resp)
- if err != nil {
- apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
- return
- }
-
- // Always return "application/jrd+json" regardless of negotiated
- // format. See https://www.rfc-editor.org/rfc/rfc7033#section-10.2
- c.Data(http.StatusOK, string(apiutil.AppJRDJSON), b)
+ // Encode JSON HTTP response.
+ apiutil.EncodeJSONResponse(
+ c.Writer,
+ c.Request,
+ http.StatusOK,
+ apiutil.AppJRDJSON,
+ resp,
+ )
}