summaryrefslogtreecommitdiff
path: root/internal/web/etag.go
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-09-18 16:33:23 +0200
committerLibravatar kim <gruf@noreply.codeberg.org>2025-09-18 16:33:23 +0200
commit6607e1c9444d0814b72762a46814ff0812d96343 (patch)
tree9bbf15038b1a37b01bfcf7010dbe376e70b504d0 /internal/web/etag.go
parent[chore] update dependencies (#4441) (diff)
downloadgotosocial-6607e1c9444d0814b72762a46814ff0812d96343.tar.xz
[feature] add paging support to rss feed endpoint, and support JSON / atom feed types (#4442)
originally based on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4396 hope this is okay https://codeberg.org/zordsdavini ! closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4411 closes https://codeberg.org/superseriousbusiness/gotosocial/issues/3407 Co-authored-by: Arnas Udovic <zordsdavini@gmail.com> Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4442 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/web/etag.go')
-rw-r--r--internal/web/etag.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/internal/web/etag.go b/internal/web/etag.go
index fcd55603b..42a6083f0 100644
--- a/internal/web/etag.go
+++ b/internal/web/etag.go
@@ -27,6 +27,7 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/log"
"codeberg.org/gruf/go-cache/v3"
+ "codeberg.org/gruf/go-fastcopy"
)
type withETagCache interface {
@@ -47,13 +48,19 @@ type eTagCacheEntry struct {
lastModified time.Time
}
-// generateEtag generates a strong (byte-for-byte) etag using
-// the entirety of the provided reader.
-func generateEtag(r io.Reader) (string, error) {
- // nolint:gosec
- hash := sha1.New()
+// generateEtag generates a strong (byte-for-byte) etag
+// using the entirety of the provided reader.
+func generateETag(r io.Reader) (string, error) {
+ return generateETagFrom(func(w io.Writer) error {
+ _, err := fastcopy.Copy(w, r)
+ return err
+ })
+}
+
+func generateETagFrom(writeTo func(io.Writer) error) (string, error) {
+ hash := sha1.New() // nolint:gosec
- if _, err := io.Copy(hash, r); err != nil {
+ if err := writeTo(hash); err != nil {
return "", err
}