serve HEAD requests via the fileserver (#735)
This commit is contained in:
parent
72650e49f7
commit
8fdc9ed552
|
@ -59,5 +59,6 @@ func (m *FileServer) Route(s router.Router) error {
|
||||||
// something like "/fileserver/:account_id/:media_type/:media_size/:file_name"
|
// something like "/fileserver/:account_id/:media_type/:media_size/:file_name"
|
||||||
fileServePath := fmt.Sprintf("%s/:%s/:%s/:%s/:%s", FileServeBasePath, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey)
|
fileServePath := fmt.Sprintf("%s/:%s/:%s/:%s/:%s", FileServeBasePath, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey)
|
||||||
s.AttachHandler(http.MethodGet, fileServePath, m.ServeFile)
|
s.AttachHandler(http.MethodGet, fileServePath, m.ServeFile)
|
||||||
|
s.AttachHandler(http.MethodHead, fileServePath, m.ServeFile)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/api"
|
"github.com/superseriousbusiness/gotosocial/internal/api"
|
||||||
|
@ -107,11 +108,18 @@ func (m *FileServer) ServeFile(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.DataFromReader(http.StatusOK, content.ContentLength, format, content.Content, map[string]string{
|
// since we'll never host different files at the same
|
||||||
// since we'll never host different files at the same
|
// URL (bc the ULIDs are generated per piece of media),
|
||||||
// URL (bc the ULIDs are generated per piece of media),
|
// it's sensible and safe to use a long cache here, so
|
||||||
// it's sensible and safe to use a long cache here, so
|
// that clients don't keep fetching files over + over again
|
||||||
// that clients don't keep fetching files over + over again
|
c.Header("Cache-Control", "max-age=604800")
|
||||||
"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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue