Add X-Cache-Hit header

This commit is contained in:
Jacob Gunther
2023-02-28 00:51:05 -06:00
parent 3c060d5794
commit fd83ed4c6b
2 changed files with 7 additions and 1 deletions

View File

@@ -49,7 +49,7 @@ func init() {
app.Use(cors.New(cors.Config{ app.Use(cors.New(cors.Config{
AllowOrigins: "*", AllowOrigins: "*",
AllowMethods: "HEAD,OPTIONS,GET", AllowMethods: "HEAD,OPTIONS,GET",
ExposeHeaders: "X-Cache-Time-Remaining", ExposeHeaders: "X-Cache-Hit,X-Cache-Time-Remaining",
})) }))
app.Use(logger.New(logger.Config{ app.Use(logger.New(logger.Config{

View File

@@ -38,6 +38,8 @@ func JavaStatusHandler(ctx *fiber.Ctx) error {
return err return err
} }
ctx.Set("X-Cache-Hit", strconv.FormatBool(expiresAt != nil))
if expiresAt != nil { if expiresAt != nil {
ctx.Set("X-Cache-Time-Remaining", strconv.Itoa(int(expiresAt.Seconds()))) ctx.Set("X-Cache-Time-Remaining", strconv.Itoa(int(expiresAt.Seconds())))
} }
@@ -62,6 +64,8 @@ func BedrockStatusHandler(ctx *fiber.Ctx) error {
return err return err
} }
ctx.Set("X-Cache-Hit", strconv.FormatBool(expiresAt != nil))
if expiresAt != nil { if expiresAt != nil {
ctx.Set("X-Cache-Time-Remaining", strconv.Itoa(int(expiresAt.Seconds()))) ctx.Set("X-Cache-Time-Remaining", strconv.Itoa(int(expiresAt.Seconds())))
} }
@@ -82,6 +86,8 @@ func IconHandler(ctx *fiber.Ctx) error {
return err return err
} }
ctx.Set("X-Cache-Hit", strconv.FormatBool(expiresAt != nil))
if expiresAt != nil { if expiresAt != nil {
ctx.Set("X-Cache-Time-Remaining", strconv.Itoa(int(expiresAt.Seconds()))) ctx.Set("X-Cache-Time-Remaining", strconv.Itoa(int(expiresAt.Seconds())))
} }