summaryrefslogtreecommitdiff
path: root/internal/api/fileserver
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-02-16 14:18:53 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-16 13:18:53 +0000
commit6ee0dc8c7df5486fd7c130a1f70712cfdd813bc4 (patch)
treefc99a51689dda8d1abd2f60d3c0641abe4c7f8a0 /internal/api/fileserver
parentFix 410 Gone race on account deletes (#1507) (diff)
downloadgotosocial-6ee0dc8c7df5486fd7c130a1f70712cfdd813bc4.tar.xz
[bugfix] Set cache-control max-age dynamically for s3 (#1510)
* [bugfix] set cache-control max-age dynamically for s3 * woops * double whoops * time until, thank you linter, bless you, you're the best, no matter what kim says * aa
Diffstat (limited to 'internal/api/fileserver')
-rw-r--r--internal/api/fileserver/servefile.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/api/fileserver/servefile.go b/internal/api/fileserver/servefile.go
index df3c83fe7..ec70ef9ae 100644
--- a/internal/api/fileserver/servefile.go
+++ b/internal/api/fileserver/servefile.go
@@ -24,6 +24,7 @@ import (
"net/http"
"strconv"
"strings"
+ "time"
"codeberg.org/gruf/go-fastcopy"
"github.com/gin-gonic/gin"
@@ -89,6 +90,10 @@ func (m *Module) ServeFile(c *gin.Context) {
if content.URL != nil {
// This is a non-local, non-proxied S3 file we're redirecting to.
+ // Derive the max-age value from how long the link has left until
+ // it expires.
+ maxAge := int(time.Until(content.URL.Expiry).Seconds())
+ c.Header("Cache-Control", "private,max-age="+strconv.Itoa(maxAge))
c.Redirect(http.StatusFound, content.URL.String())
return
}