From 5df3fd9d2544cb4d6ed82015d632ec362c508e80 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= <mordae@anilinux.org>
Date: Tue, 30 Apr 2019 23:56:07 +0200
Subject: [PATCH] Showcase wrapping a little bit more
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Jan Hamal Dvořák <mordae@anilinux.org>
---
 examples/Simple.hs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/examples/Simple.hs b/examples/Simple.hs
index 86c658b..442b8d9 100644
--- a/examples/Simple.hs
+++ b/examples/Simple.hs
@@ -21,6 +21,7 @@ where
   import Control.Monad.Reader
   import Data.Text (Text)
   import Lucid
+  import Network.HTTP.Types.Header
   import Network.HTTP.Types.Status
   import Network.Wai
   import Network.Wai.Handler.Warp
@@ -98,9 +99,14 @@ where
       -- Plug in a cool logging middleware.
       middleware $ logStdoutDev
 
-      -- Negotiate content for the root page.
-      route $ getRootHtmlR <$ get <* offerHTML
-      route $ getRootTextR <$ get <* offerText
+      -- Enable 300s cache for the static endpoints.
+      wrapAction (defaultHeader hCacheControl "public, max-age=300" >>) $ do
+        -- Negotiate content for the root page.
+        route $ getRootHtmlR <$ get <* offerHTML
+        route $ getRootTextR <$ get <* offerText
+
+      -- Disable caching for all the following endpoints.
+      wrapActions (defaultHeader hCacheControl "no-store" >>)
 
       -- Present a simple greeting page.
       route $ getHelloR <$ get <* seg "hello" <*> arg
-- 
GitLab