diff options
author | 2023-07-13 21:27:25 +0200 | |
---|---|---|
committer | 2023-07-13 21:27:25 +0200 | |
commit | 12b6cdcd8ce52269be5a1ca8acaae006896808b5 (patch) | |
tree | eba84aa522ba2ccbfb539930789a046630d03dae /internal/api/fileserver.go | |
parent | [chore] Skip webfinger test on CI (#1983) (diff) | |
download | gotosocial-12b6cdcd8ce52269be5a1ca8acaae006896808b5.tar.xz |
[bugfix] Set Vary header correctly on cache-control (#1988)v0.10.0-rc2
* [bugfix] Set Vary header correctly on cache-control
* Prefer activitypub types on AP endpoints
* use immutable on file server, vary by range
* vary auth on Accept
Diffstat (limited to 'internal/api/fileserver.go')
-rw-r--r-- | internal/api/fileserver.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/internal/api/fileserver.go b/internal/api/fileserver.go index 9a2fdd633..8f1e60b82 100644 --- a/internal/api/fileserver.go +++ b/internal/api/fileserver.go @@ -36,8 +36,8 @@ func (f *Fileserver) Route(r router.Router, m ...gin.HandlerFunc) { // Attach middlewares appropriate for this group. fileserverGroup.Use(m...) // If we're using local storage or proxying s3, we can set a - // long max-age on all file requests to reflect that we - // never host different files at the same URL (since + // long max-age + immutable on all file requests to reflect + // that we never host different files at the same URL (since // ULIDs are generated per piece of media), so we can // easily prevent clients having to fetch files repeatedly. // @@ -45,9 +45,18 @@ func (f *Fileserver) Route(r router.Router, m ...gin.HandlerFunc) { // must be set dynamically within the request handler, // based on how long the signed URL has left to live before // it expires. This ensures that clients won't cache expired - // links. This is done within fileserver/servefile.go. + // links. This is done within fileserver/servefile.go, so we + // should not set the middleware here in that case. + // + // See: + // + // - https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching#avoiding_revalidation + // - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#immutable if config.GetStorageBackend() == "local" || config.GetStorageS3Proxy() { - fileserverGroup.Use(middleware.CacheControl("private", "max-age=604800")) // 7d + fileserverGroup.Use(middleware.CacheControl(middleware.CacheControlConfig{ + Directives: []string{"private", "max-age=604800", "immutable"}, + Vary: []string{"Range"}, // Cache partial ranges separately. + })) } f.fileserver.Route(fileserverGroup.Handle) |