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/wellknown/hostmeta | |
| 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/wellknown/hostmeta')
| -rw-r--r-- | internal/api/wellknown/hostmeta/hostmetaget.go | 27 |
1 files changed, 8 insertions, 19 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, + ) } |
