From 0f5b85a0636808d2801f1a3479295750d1b484f5 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Fri, 13 Nov 2026 13:09:15 -0500 Subject: [PATCH] cache control header on content endpoint --- handlers.go | 6 ++++++ readme.md | 18 ++++++++++-------- templates/tos.html | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/handlers.go b/handlers.go index f4556ab..5a58e50 100644 --- a/handlers.go +++ b/handlers.go @@ -310,6 +310,12 @@ func contentHandler(db *gorm.DB, cfg Config) http.HandlerFunc { defer file.Close() + ttl := 600 // 10 minutes + if upload.ExpiresAt != nil { + ttl = int(*upload.ExpiresAt - now) + } + + w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d, must-revalidate", ttl)) w.Header().Set("Content-Type", upload.MIMEType) w.Header().Set("X-Content-Type-Options", "nosniff") http.ServeContent(w, r, upload.Filename, time.Unix(upload.CreatedAt, 0), file) diff --git a/readme.md b/readme.md index b0f83a3..ee71662 100644 --- a/readme.md +++ b/readme.md @@ -14,15 +14,14 @@ goals: - moderable (reports, mime type filtering, hash ban, etc) - complete no javascript support - # roadmap/todo + - [x] upload endpoint - [x] content endpoint - - [ ] update last accessed at - - use a memory cache and batch commit to database to keep performance - - [ ] add cache control headers - - [ ] add a config option to put the endpoint on another path, such as `/f/{id}` - - allowing more specific caching options through reverse proxies like cloudflare + - [ ] update last accessed at + - use a memory cache and batch commit to database to keep performance + - [x] add cache control headers + - [x] delete content endpoints - [ ] paste page - [ ] return a page for nojs clients, such as on delete or upload @@ -33,10 +32,13 @@ goals: - [ ] prometheus metrics - [x] [switch mime type detection library](https://git.whoswhip.dev/whoswhip/minibin/src/commit/47518993577f94d7cf9c0743042d2ac133055924/handlers.go#L273-L276) - [ ] ratelimits +- [ ] simplify rendering & serving pages (too much duplicate code rn) ## misc goals - [x] link to this git repo on home page - [ ] maybe keep nojs and js on the same page? - - just use javascript to enhance the experience, like progress, drag and drop -- [ ] shareX config download handlers (automatically create based off of config) \ No newline at end of file + - just use javascript to enhance the experience, like progress, drag and drop +- [ ] shareX config download handlers (automatically create based off of config) +- [ ] add a config option to put the endpoint on another path, such as `/f/{id}` + - allowing more specific caching options through reverse proxies like cloudflare diff --git a/templates/tos.html b/templates/tos.html index bf9ca57..4d177fc 100644 --- a/templates/tos.html +++ b/templates/tos.html @@ -20,7 +20,7 @@

do not upload or share: