From d4dd9fa7e36729a7738b75e54b440e80f5c5f9c1 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Mon, 9 May 2022 15:38:40 +0200 Subject: [PATCH] Set cache-control headers for static routes (getinfor and home) This tells clients to cache the response for a few minutes and thus makes it easier to run lndhub behind a proxy to cache static response --- controllers/getinfo.ctrl.go | 2 ++ controllers/home.ctrl.go | 1 + 2 files changed, 3 insertions(+) diff --git a/controllers/getinfo.ctrl.go b/controllers/getinfo.ctrl.go index d8c118e..a030ce0 100644 --- a/controllers/getinfo.ctrl.go +++ b/controllers/getinfo.ctrl.go @@ -95,5 +95,7 @@ func (controller *GetInfoController) GetInfo(c echo.Context) error { } // BlueWallet right now requires a `identity_pubkey` in the response // https://github.com/BlueWallet/BlueWallet/blob/a28a2b96bce0bff6d1a24a951b59dc972369e490/class/wallets/lightning-custodian-wallet.js#L578 + + c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=300, stale-if-error=21600") // cache for 5 minutes or if error for 6 hours max return c.JSON(http.StatusOK, info) } diff --git a/controllers/home.ctrl.go b/controllers/home.ctrl.go index 96e546a..d23d74d 100644 --- a/controllers/home.ctrl.go +++ b/controllers/home.ctrl.go @@ -117,6 +117,7 @@ func (controller *HomeController) Home(c echo.Context) error { if err != nil { return err } + c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=300, stale-if-error=21600") // cache for 5 minutes or if error for 6 hours max return c.HTMLBlob(http.StatusOK, buf.Bytes()) }