summaryrefslogtreecommitdiff
path: root/internal/api/client/fileserver/servefile.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-07-30 14:42:47 +0200
committerLibravatar GitHub <noreply@github.com>2022-07-30 13:42:47 +0100
commit8fdc9ed5528fb99949fbe8851065ca3d59cc1ac3 (patch)
treed4bc553b0f730717262c2ddf2d0e1e3ce61d75f2 /internal/api/client/fileserver/servefile.go
parent[frontend] Update client list and apply some minor fixes (#734) (diff)
downloadgotosocial-8fdc9ed5528fb99949fbe8851065ca3d59cc1ac3.tar.xz
serve HEAD requests via the fileserver (#735)
Diffstat (limited to 'internal/api/client/fileserver/servefile.go')
-rw-r--r--internal/api/client/fileserver/servefile.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/internal/api/client/fileserver/servefile.go b/internal/api/client/fileserver/servefile.go
index fffa15a1c..0858af3ce 100644
--- a/internal/api/client/fileserver/servefile.go
+++ b/internal/api/client/fileserver/servefile.go
@@ -22,6 +22,7 @@ import (
"fmt"
"io"
"net/http"
+ "strconv"
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api"
@@ -107,11 +108,18 @@ func (m *FileServer) ServeFile(c *gin.Context) {
return
}
- c.DataFromReader(http.StatusOK, content.ContentLength, format, content.Content, map[string]string{
- // since we'll never host different files at the same
- // URL (bc the ULIDs are generated per piece of media),
- // it's sensible and safe to use a long cache here, so
- // that clients don't keep fetching files over + over again
- "Cache-Control": "max-age=604800",
- })
+ // since we'll never host different files at the same
+ // URL (bc the ULIDs are generated per piece of media),
+ // it's sensible and safe to use a long cache here, so
+ // that clients don't keep fetching files over + over again
+ c.Header("Cache-Control", "max-age=604800")
+
+ if c.Request.Method == http.MethodHead {
+ c.Header("Content-Type", format)
+ c.Header("Content-Length", strconv.FormatInt(content.ContentLength, 10))
+ c.Status(http.StatusOK)
+ return
+ }
+
+ c.DataFromReader(http.StatusOK, content.ContentLength, format, content.Content, nil)
}