diff options
| author | 2023-11-27 14:00:57 +0000 | |
|---|---|---|
| committer | 2023-11-27 14:00:57 +0000 | |
| commit | 74700cc8034980334e7df466f313287a41d2b8a6 (patch) | |
| tree | 63ab8912c813eefba8a492e0d0489f4e5fe59446 /internal/api/activitypub/publickey | |
| parent | [chore]: Bump codeberg.org/gruf/go-mutexes from 1.3.0 to 1.3.1 (#2387) (diff) | |
| download | gotosocial-74700cc8034980334e7df466f313287a41d2b8a6.tar.xz | |
[performance] http response encoding / writing improvements (#2374)
Diffstat (limited to 'internal/api/activitypub/publickey')
| -rw-r--r-- | internal/api/activitypub/publickey/publickeyget.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/internal/api/activitypub/publickey/publickeyget.go b/internal/api/activitypub/publickey/publickeyget.go index a7de4efad..083a31961 100644 --- a/internal/api/activitypub/publickey/publickeyget.go +++ b/internal/api/activitypub/publickey/publickeyget.go @@ -18,7 +18,6 @@ package publickey import ( - "encoding/json" "errors" "net/http" "strings" @@ -42,13 +41,13 @@ func (m *Module) PublicKeyGETHandler(c *gin.Context) { return } - format, err := apiutil.NegotiateAccept(c, apiutil.ActivityPubOrHTMLHeaders...) + contentType, err := apiutil.NegotiateAccept(c, apiutil.ActivityPubOrHTMLHeaders...) if err != nil { apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) return } - if format == string(apiutil.TextHTML) { + if contentType == string(apiutil.TextHTML) { // redirect to the user's profile c.Redirect(http.StatusSeeOther, "/@"+requestedUsername) return @@ -60,11 +59,12 @@ func (m *Module) PublicKeyGETHandler(c *gin.Context) { return } - b, err := json.Marshal(resp) - if err != nil { - apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1) - return - } - - c.Data(http.StatusOK, format, b) + // Encode JSON HTTP response. + apiutil.EncodeJSONResponse( + c.Writer, + c.Request, + http.StatusOK, + contentType, + resp, + ) } |
