[performance] http response encoding / writing improvements (#2374)

This commit is contained in:
kim 2023-11-27 14:00:57 +00:00 committed by GitHub
commit 74700cc803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
104 changed files with 526 additions and 267 deletions

View file

@ -18,7 +18,6 @@
package users
import (
"encoding/json"
"errors"
"net/http"
"strings"
@ -39,13 +38,13 @@ func (m *Module) FollowersGETHandler(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) {
// This isn't an ActivityPub request;
// redirect to the user's profile.
c.Redirect(http.StatusSeeOther, "/@"+requestedUsername)
@ -68,11 +67,5 @@ func (m *Module) FollowersGETHandler(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)
apiutil.JSONType(c, http.StatusOK, contentType, resp)
}