bskyweb: do not serve cache headers on non-2XX for static assets (#7469)

This commit is contained in:
devin ivy
2025-01-17 12:36:58 -05:00
committed by GitHub
parent c84158fa8b
commit ec9cafdbbd
+6
View File
@@ -214,6 +214,11 @@ func serve(cctx *cli.Context) error {
e.GET("/iframe/youtube.html", echo.WrapHandler(staticHandler))
e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", staticHandler)), func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Before(func() {
if c.Response().Status >= 300 {
return
}
path := c.Request().URL.Path
maxAge := 1 * (60 * 60) // default is 1 hour
@@ -223,6 +228,7 @@ func serve(cctx *cli.Context) error {
}
c.Response().Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", maxAge))
})
return next(c)
}
})